I am building an iOS app in Swift 4 and I am trying to add a song to the users Apple Music Library, I am able to get my Apple Music Library like so:
mediaPicker = MPMediaPickerController(mediaTypes: .anyAudio)
mediaPicker?.showsCloudItems = false
mediaPicker?.showsItemsWithProtectedAssets = false
if let picker = mediaPicker{
picker.delegate = self
picker.allowsPickingMultipleItems = false
present(picker, animated: true, completion: nil)
}
But is it possible to upload a song to the users Apple Music Library?
Here is how I am getting the audio file that I wish to add to the users Apple Music Library
let audioString = (result[0]["audio"] as! String).addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)
let audioUrl = URL(string:"http://example.com/uploads/" + audioString!)
Alamofire.request(audioUrl!).responseData { response in
do {
self.audio = try AVAudioPlayer(data: response.data!)
self.audio?.prepareToPlay()
}catch{
}
}
UPDATE
I found this: https://stackoverflow.com/a/17433006/979331 Now I have 2 questions, how would I convert this to Swift and if I use ScriptingBridge will this be allowed when I submit my app to the app store?