1

I have followed Apple's MusicKit sample code at https://developer.apple.com/musickit/ and am unable to get the setup view controller to display. I simplified the sample code into a separate project, here: https://github.com/higginator/SubscribePlaybackAppleMusic.

I follow the documented procedure:

  1. request apple music authorization
  2. request apple music capabilities
  3. if subscription is eligibile, setup the subscription view

Here is the sample:

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Authorize" style:UIBarButtonItemStylePlain target:self action:@selector(authorizeAppleMusic)];
_cloudServiceController = [[SKCloudServiceController alloc] init];
_setupVC = [[SKCloudServiceSetupViewController alloc] init];
_setupVC.delegate = self;

}

- (void)authorizeAppleMusic {
switch ([SKCloudServiceController authorizationStatus]) {
    case SKCloudServiceAuthorizationStatusNotDetermined:
        NSLog(@"auth not determined");
        [self requestAppleMusicAuthorization];
        break;
    case SKCloudServiceAuthorizationStatusDenied:
        NSLog(@"auth denied");
        break;
    case SKCloudServiceAuthorizationStatusRestricted:
        NSLog(@"auth restricted");
        break;
    case SKCloudServiceAuthorizationStatusAuthorized:
        NSLog(@"authorized");
        [self appleMusicCapabilities];
        break;
}

}

- (void)requestAppleMusicAuthorization {
[SKCloudServiceController requestAuthorization:^(SKCloudServiceAuthorizationStatus status) {
    if (status == SKCloudServiceAuthorizationStatusAuthorized) {
        [self appleMusicCapabilities];
    }
}];

}

- (void)appleMusicCapabilities {
[self.cloudServiceController
 requestCapabilitiesWithCompletionHandler:^(SKCloudServiceCapability capabilities,
                                            NSError * _Nullable error) {
     switch (capabilities) {
         case SKCloudServiceCapabilityNone:
             NSLog(@"apple music none");
             break;
         case SKCloudServiceCapabilityMusicCatalogPlayback:
             NSLog(@"apple music playback");
             break;
         case SKCloudServiceCapabilityMusicCatalogSubscriptionEligible:
             NSLog(@"apple music subscription eligible");
             [self setupSubscriptionVC];
             break;
         case SKCloudServiceCapabilityAddToCloudMusicLibrary:
             NSLog(@"apple music add to cloud music library");
             break;
     }
}];

}

- (void)setupSubscriptionVC {
NSDictionary<SKCloudServiceSetupOptionsKey, id> *appleMusicOptions =
@{SKCloudServiceSetupOptionsActionKey: SKCloudServiceSetupActionSubscribe};
NSLog(@"apple music options: %@", appleMusicOptions);
[self.setupVC loadWithOptions:appleMusicOptions
            completionHandler:^(BOOL result, NSError * _Nullable error) {
                NSLog(@"setupvc completion handler");
                if (error) {
                    NSLog(@"setupvc error: %@", [error localizedDescription]);
                }
                if (result) {
                    NSLog(@"setupvc load complete");
                    [self presentViewController:self.setupVC animated:YES completion:nil];
                }
            }];

}

In both my sample project provided and Apple's sample code, the setup view controller is not loaded and not presented. What can I do to present the setup view controller?

R H
  • 11
  • 2

1 Answers1

0

At first, you should use real device instead of simulator. At second, you should have iTunes installed on your device. And you should present your SKCloudServiceSetupViewController using its parent ViewController:

[parentViewController presentViewController:myCloudServiceSetupViewController animated:YES completion:nil];