4

It seems that the general MPMediaPicker is not working anymore on ios13 (ipad air 2, iphone SE)

The example 1:1 copied from there is not showing up the media picker https://developer.apple.com/documentation/mediaplayer/displaying_a_media_picker_from_your_app

Any tips how to get back functionality??

Note 1

When using using the MPMediaPickerController like this

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

The delegate is not invoked at all. No log is shown, only the native alert.

I am getting this native altert

Internal Error

The requested app extension could not be found

[Cancel]

Note 2

It seems to be the issue when the apple music app is not installed on that device. Does anybody know a reliable way to find out if apple music app is installed?

Community
  • 1
  • 1
Martin Mlostek
  • 2,755
  • 1
  • 28
  • 57

3 Answers3

4

It seems that the Music app from apple has to be installed on that device. Still not 100% reproducible, but with that app installed, I never saw that issue again.

Martin Mlostek
  • 2,755
  • 1
  • 28
  • 57
0

did you set the permission for the Media Library in your info.plist? NSAppleMusicUsageDescription

ferbass
  • 859
  • 5
  • 17
0

From iOS 13 MPMediaPicker required user authorization, unlike the earlier iOS version. So you need to handle the authentication first and then show the picker if user granted the permission. You code will be as follow,

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];
}
iEngineer
  • 1,319
  • 1
  • 11
  • 27