This is the code I use:
@MainActor func picker()->UIViewController{
let pickerController = MPMediaPickerController(mediaTypes: .music)
print(pickerController)
pickerController.showsCloudItems=true
pickerController.prompt = NSLocalizedString("Add pieces to queue", comment:"");
pickerController.allowsPickingMultipleItems=true;
pickerController.delegate=MPMusicPlayerControllerSingleton.sharedController();
return pickerController
}
MainActor
@IBAction func handleBrowserTapped(_ sender: AnyObject){
if let pickerController=contentProvider?.picker(){
self.present(pickerController, animated:true, completion:nil)
}
}
And this his is the crash log:
*** Assertion failure in -[MPMediaPickerController_Appex requestRemoteViewController], MPMediaPickerController.m:523
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'remoteViewController cannot be nil -- process will crash inserting in hierarchy. We likely got a nil remoteViewController because Music is crashing.'
*** First throw call stack:
(0x1869cac70 0x183499224 0x1844f9f50 0x1a6c6a060 0x18d45518c 0x18d4cd410 0x103354544 0x10336dccc 0x10338f748 0x103364204 0x103364144 0x186957a64 0x1868e5288 0x1868e41d0 0x22bde7498 0x18c5a5ca0 0x18c510254 0x18c71ce90 0x103854340 0x1038542b0 0x103854430 0x1834f1c1c)
libc++abi: terminating due to uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'remoteViewController cannot be nil -- process will crash inserting in hierarchy. We likely got a nil remoteViewController because Music is crashing.'