MPMediaPickerController空白屏幕,各种错误,正确的Info.plist文件(iOS 13.1.3)



我试图让用户从他们的音乐库中选择一首歌。因此,问题在于:MPMediaPickerController 显示白屏,并在全新安装应用程序后锁定应用程序,并且仅在用户授予权限后锁定应用程序。退出应用并重新启动不会重现错误(可能是因为已授予权限(。删除应用程序并重新安装会重现该错误。

  • 我已确保我的Info.plist文件包含正确的信息
  • 我已经确保媒体选择器显示在主 线
  • 我尝试在我的视图控制器上创建一个属性来保存 对 MPMediaPickerController 实例的强引用,以确保 它没有从内存中删除(为什么不尝试?
  • 我擁有有效的 Apple Music 訂閱,並已登入 iCloud 使用有效的苹果 ID
  • 我的裝置已在 iTunes Connect 上註冊(或任何名稱( 并具有有效的预配配置文件
  • 这是在iOS 13.1.3上。

以下是我初始化选取器的方法(我也尝试通过在视图控制器上分配属性(:

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)

这是我的Info.plist文件中的相关行:

<key>NSAppleMusicUsageDescription</key>
<string>Use tracks from your iTunes library as wakeup sounds</string>

在控制台中,我收到以下错误:

[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)

我的猜测?SQLite 位于不同线程中的一些竞争条件同步问题仅在等待用户授予权限时出现问题。这甚至可以在我这边修复吗?

我不想有白屏死机!有什么建议吗?

过去,您可能在没有首先请求和获得用户授权的情况下呈现媒体选择器,但在iOS 13中,情况已不再如此。在提供媒体选取器之前,必须明确确保您具有授权:

let status = MPMediaLibrary.authorizationStatus()
switch status {
case .authorized:
// ok to present the picker
case .notDetermined:
MPMediaLibrary.requestAuthorization() { status in
if status == .authorized {
// get on main thread, ok to present the picker
// ...

如果您在尚未获得授权时出示选取器,它将如您所描述的那样冻结。

正如您所描述的,您还需要Info.plist条目,但仅此还不够。需要Info.plist条目和用户权限,然后才能显示选取器。没有前者,你会崩溃。如果没有后者,您将获得冻结的白屏。有了两者,一切都会好起来的。

对我来说,选择的答案不是问题,尽管绝对需要授权和Info.plist。我最初在ViewDidLoad中设置了MPMediaPickerController,然后在IBAction函数中展示了视图控制器。有时它会起作用,有时我得到空白屏幕。

在查看了 Apple 文档后,所有这些代码实际上都应该在 IBAction 中,包括设置委托,否则委托函数将不会被调用。

显示应用中的媒体选取器

@IBAction func selectSong(_ sender: UIButton) {
let picker = MPMediaPickerController(mediaTypes: .music)
picker.allowsPickingMultipleItems = false
picker.popoverPresentationController?.sourceView = sender
picker.delegate = self
self.present(picker, animated: true, completion: nil)
}

最新更新