Skip to content

Instantly share code, notes, and snippets.

@zonble
Created April 25, 2016 15:28
Show Gist options
  • Save zonble/10d7a493cdaa2d4f3fac5fedf4135edb to your computer and use it in GitHub Desktop.
Save zonble/10d7a493cdaa2d4f3fac5fedf4135edb to your computer and use it in GitHub Desktop.
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()
}
}
}
}
}
}
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