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

Posted

技术标签:

【中文标题】iOS 13:MPMediaPickerController - 内部错误/找不到请求的应用扩展【英文标题】:iOS 13: MPMediaPickerController - Internal Error / The requested app extension could not be found 【发布时间】:2019-10-12 10:52:07 【问题描述】:

看来一般MPMediaPickerios13(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

这似乎是该设备上未安装苹果音乐应用程序的问题。有人知道确定是否安装了苹果音乐应用的可靠方法吗?

【问题讨论】:

我认为您需要使用预配置的设备,模拟器无法访问任何媒体库。 我主要在真实设备上工作。那里也一样 @matt 在您卸载 appla 应用程序“音乐”时对您有用吗? 你能在哪里解决这个问题? 不。如果没有安装 Apple 音乐应用程序,它仍然会发生 【参考方案1】:

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

【讨论】:

【参考方案2】:

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

【讨论】:

是的。就这样添加了【参考方案3】:

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

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];

【讨论】:

当您卸载苹果应用程序“音乐”时,此示例是否也适用于您

以上是关于iOS 13:MPMediaPickerController - 内部错误/找不到请求的应用扩展的主要内容,如果未能解决你的问题,请参考以下文章

iOS 13设置 tabbar字体

iOS13.6越狱有望/iOS13.6以及iOS12.4.8推送更新/苹果加入新人权Emoji表情

iOS 13.6 降级 13.4.1 系统,FilzaEscaped 进展

iOS13系统UITabBar

iOS 13.5.1iOS 12.4.7 验证关闭,用户无法刷机

iOS 13.6 续航对比出炉,成绩垫底/ iPhone 12 电池容量曝光/ iOS 13.5.1 验证关闭