iOS 13:MPMediaPickerController语言 - 内部错误/找不到请求的应用扩展



似乎一般MPMediaPicker在ios13(ipad air 2,iphone SE(上不再工作

从那里复制的示例 1:1 未显示媒体选取器 https://developer.apple.com/documentation/mediaplayer/displaying_a_media_picker_from_your_app

任何提示如何恢复功能?

注1

使用这样的MPMediaPickerController

musicPickerView = [[UIView alloc] initWithFrame:fullScreenRect];
musicPickerView.alpha = 0.0f;
musicPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
musicPicker.showsCloudItems               = false;
musicPicker.showsItemsWithProtectedAssets = false;
musicPicker.delegate                      = self;
musicPicker.allowsPickingMultipleItems    = false;
musicPicker.prompt                        = NSLocalizedString(@"Select a song", @"Select a song");
musicPicker.view.frame                    = musicPickerView.bounds;
[self addChildViewController:musicPicker];
[musicPickerView addSubview:musicPicker.view];
[self.view addSubview:musicPickerView];
[musicPicker didMoveToParentViewController:self];
[self fadeInMusicPicker:true];

根本不调用委托。不显示日志,仅显示本机警报。

我正在得到这个本地替代

内部错误

找不到请求的应用扩展

[取消]

注2

当苹果音乐应用程序未安装在该设备上时,这似乎是问题所在。有谁知道一种可靠的方法来找出是否安装了苹果音乐应用程序?

似乎必须将Apple的Music应用程序安装在该设备上。仍然不是 100% 可重现的,但是安装了该应用程序后,我再也没有看到过这个问题。

您是否在info.plist中设置了媒体库的权限?NSAppleMusicUsageDescription

FromiOS 13MPMediaPicker需要用户授权,这与早期的iOS版本不同。因此,您需要先处理身份验证,然后在用户授予权限时显示选取器。你的代码将如下所示,

MPMediaLibraryAuthorizationStatus authorizationStatus = MPMediaLibrary.authorizationStatus;
switch (authorizationStatus)
{
case MPMediaLibraryAuthorizationStatusAuthorized:
{
[self showPickerView];
break;
}
case MPMediaLibraryAuthorizationStatusNotDetermined:
{
// Not yet authorized - request it from the system
[MPMediaLibrary requestAuthorization:^(MPMediaLibraryAuthorizationStatus authorizationStatus)
{
if ( authorizationStatus == MPMediaLibraryAuthorizationStatusAuthorized )
{
dispatch_async(dispatch_get_main_queue(), ^{
[self showPickerView];
});
}
else
{
PLog(@"The Media Library was not authorized by the user");
}
}];
break;
}
case MPMediaLibraryAuthorizationStatusRestricted:
case MPMediaLibraryAuthorizationStatusDenied:
{
// user has previously denied access. Ask again with our own alert that is similar to the system alert
// then take them to the System Settings so they can turn it on for the app
break;
}
}

-(void)showPickerView
{
musicPickerView = [[UIView alloc] initWithFrame:fullScreenRect];
musicPickerView.alpha = 0.0f;
musicPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
musicPicker.showsCloudItems               = false;
musicPicker.showsItemsWithProtectedAssets = false;
musicPicker.delegate                      = self;
musicPicker.allowsPickingMultipleItems    = false;
musicPicker.prompt                        = NSLocalizedString(@"Select a song", @"Select a song");
musicPicker.view.frame                    = musicPickerView.bounds;
[self addChildViewController:musicPicker];
[musicPickerView addSubview:musicPicker.view];
[self.view addSubview:musicPickerView];
[musicPicker didMoveToParentViewController:self];
[self fadeInMusicPicker:true];
}

相关内容

  • 没有找到相关文章

最新更新