I'm trying to let users choose a song from their music library. So, the problem: MPMediaPickerController displays a white screen and locks the app after a fresh install of the app and only after the user grants permission. Quitting the app and restarting it doesn't reproduce the error (perhaps because permissions have already been granted). Deleting the app and reinstalling reproduces the error.
- I've made sure my
Info.plist
file has the correct information - I have made sure the media picker is being presented on the main thread
- I have tried creating a property on my ViewController to hold a strong reference to the MPMediaPickerController instance to make sure it wasn't getting removed from memory (why not try?)
- I have a valid Apple Music subscription and I'm signed into iCloud with a valid Apple ID
- My device is registered on iTunes Connect (or whatever the name is) and has a valid provisioning profile
- This is on iOS 13.1.3.
Here's how I initialize the picker (I've also tried by assigning a property on the view controller):
let picker = MPMediaPickerController(mediaTypes: .music)
picker.allowsPickingMultipleItems = false // I've tried commenting this out
picker.popoverPresentationController?.sourceView = cell // I've tried commenting this out
picker.delegate = self // I've tried commenting this out
picker.prompt = "Choose a song" // I've tried commenting this out
self.present(picker, animated: true, completion: nil)
Here's the relevant line in my Info.plist file:
<key>NSAppleMusicUsageDescription</key>
<string>Use tracks from your iTunes library as wakeup sounds</string>
In the console, I get the following errors:
[MediaLibrary] SQLite error 14 detected while opening database '/var/mobile/Media/iTunes_Control/iTunes/MediaLibrary.sqlitedb'
[MediaLibrary] DISK IO ERROR: attempting to close and re-open connection for recovery.
[MediaLibrary] [_handleDiskIOError] checking database consistency
[Service] Failed to obtain service proxy to perform integrity check. err=Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.medialibraryd.xpc" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.medialibraryd.xpc} There was an error waiting for a reply from the media library service. Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.medialibraryd.xpc" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.medialibraryd.xpc}
[MediaLibrary] [_handleDiskIOError] failed to re-open database connection
[MediaLibrary] [_handleDiskIOError] FAILED TO HANDLE DISK IO ERROR
[MediaLibrary] [_handleDiskIOError] SHM file not found—unable to unlink
[MediaLibrary] [ML3DatabaseConnection] Unable to open database connection to path /var/mobile/Media/iTunes_Control/iTunes/MediaLibrary.sqlitedb. unable to open database file
[Service] Could not attempt recovery at path: /var/mobile/Media/iTunes_Control/iTunes/MediaLibrary.sqlitedb There was an error waiting for a reply from the media library service. Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.medialibraryd.xpc" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.medialibraryd.xpc}
[xpc.exceptions] <NSXPCConnection: 0x281a5f3c0> connection to service on pid 466 named com.apple.Music.MediaPicker.viewservice: Exception caught during decoding of received selector remoteMediaPickerDidPickMediaItems:, dropping incoming message.
Exception: Exception while decoding argument 0 (#2 of invocation):
<NSInvocation: 0x283203a00>
return value: {v} void
target: {@} 0x0
selector: {:} null
argument 2: {@} 0x0
Exception: Could not open database file at /var/mobile/Media/iTunes_Control/iTunes/MediaLibrary.sqlitedb (errno = 1)
My guess? Some race-condition sync issue with SQLite being in a different thread that's only a problem when waiting for the user to grant permissions. Is this even fixable on my end?
I'd like to not have a white screen of death! Any suggestions?