Created
April 25, 2016 15:28
-
-
Save zonble/10d7a493cdaa2d4f3fac5fedf4135edb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import StoreKit | |
import MediaPlayer | |
class AppleProductPlayer: NSObject { | |
func play(productID: String) { | |
SKCloudServiceController.requestAuthorization { status in | |
let cloudServiceController = SKCloudServiceController() | |
cloudServiceController.requestCapabilitiesWithCompletionHandler { cloudServiceCapability, error in | |
if cloudServiceCapability.contains(.AddToCloudMusicLibrary) { | |
MPMediaLibrary.defaultMediaLibrary().addItemWithProductID(productID) { entities, error in | |
MPMusicPlayerController.systemMusicPlayer().setQueueWithStoreIDs([productID]) | |
MPMusicPlayerController.systemMusicPlayer().play() | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController { | |
let player = AppleProductPlayer() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
player.play("1073160426") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment