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

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

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

【问题讨论】:

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

标签: ios xcode mpmediaitem mpmediapickercontroller apple-music


【解决方案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];
    }
    

    【讨论】:

    • 当您卸载苹果应用程序“音乐”时,此示例是否也适用于您
    猜你喜欢
    • 2020-01-21
    • 2022-06-14
    • 2020-10-10
    • 1970-01-01
    • 1970-01-01
    • 2011-09-17
    • 2016-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多