1

我在https://developer.apple.com/musickit/上遵循了 Apple 的 MusicKit 示例代码,但无法显示设置视图控制器。我将示例代码简化为一个单独的项目,在这里:https ://github.com/higginator/SubscribePlaybackAppleMusic 。

我遵循记录在案的程序:

  1. 请求苹果音乐授权
  2. 请求苹果音乐功能
  3. 如果订阅符合条件,则设置订阅视图

这是示例:

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

}

在我提供的示例项目和 Apple 的示例代码中,设置视图控制器都未加载且未显示。我可以做些什么来展示设置视图控制器?

4

1 回答 1

0

首先,您应该使用真实设备而不是模拟器。其次,您应该在您的设备上安装 iTunes。你应该使用它的父 ViewController 来展示你的 SKCloudServiceSetupViewController:

[parentViewController presentViewController:myCloudServiceSetupViewController animated:YES completion:nil];
于 2018-07-20T13:48:41.843 回答