以下是获取用户令牌的代码
NSString *developerToken = @"eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IlVaMzI1Q0MyMkcifQ.eyJpc3MiOiJEWjI4TDk1OFBCIiwiaWF0IjoxNTI1MjY1NjE0LCJleHAiOjE1Mzg0Mzg0MDB9.frMVLzCx3oaUyqcBzZvSoB60LjCrtqmiCwf-ouQ1Y12UYpW5w8R-cmAX6N_Fwpz_l5CFe3OkYP3uET7uCPvyOw";
[SKCloudServiceController requestAuthorization:^(SKCloudServiceAuthorizationStatus status) {
self->cloudServiceController = [[SKCloudServiceController alloc] init];
[self->cloudServiceController requestCapabilitiesWithCompletionHandler:^(SKCloudServiceCapability capabilities, NSError * _Nullable error) {
[self->cloudServiceController requestStorefrontIdentifierWithCompletionHandler:^(NSString * _Nullable storefrontIdentifier,
NSError * _Nullable error) {
NSString *identifier = [[storefrontIdentifier componentsSeparatedByString:@","] firstObject];
identifier = [[identifier componentsSeparatedByString:@"-"] firstObject];
if (@available(iOS 11.0, *)) {
[self->cloudServiceController requestUserTokenForDeveloperToken:developerToken completionHandler:^(NSString * _Nullable userToken, NSError * _Nullable error) {
NSLog(@"%@",error);
NSLog(@"%@",userToken);
}];
} else {
// Fallback on earlier versions
}
//NSString *countryCode = [self countryCodeWithIdentifier:identifier];
}];
}];
}];
但是我将userToken设为nil,错误为
"错误域= SKErrorDomain代码= 7"(null)" UserInfo = {NSUnderlyingError = 0x1c08437b0 {错误域= SSErrorDomain 代码= 109"(null)" UserInfo = {NSUnderlyingError = 0x1c08437e0 {错误 Domain = SSErrorDomain Code = 109"无法连接到iTunes Store" UserInfo = {NSLocalizedDescription =无法连接到iTunes Store, SSErrorHTTPStatusCodeKey = 401}}}}}"
我做错了什么?请帮忙
答案 0 :(得分:0)
错误代码SSErrorHTTPStatusCodeKey=401
通常表示它是未经授权的请求,它向我表明您的开发人员令牌无效。您确定这是一个格式正确,未过期的开发人员令牌吗?
答案 1 :(得分:0)
对我个人而言,问题不是订阅Apple Music ;我遇到了相同的错误(“错误域= SKErrorDomain代码= 7”)。
解决此问题的一种方法是检查用户是否拥有Apple Music帐户。 为此(通过Apple文档)
快速:
controller.requestCapabilities {(capabilities: SKCloudServiceCapability, error: Error?) in
guard error == nil else { return }
if capabilities.contains(.musicCatalogPlayback) {
// CASE WHERE USER HAS APPLE MUSIC SUBSCRIPTION
// GET USER TOKEN HERE
}
}
Objective-C :
[controller requestCapabilitiesWithCompletionHandler:^(SKCloudServiceCapability capabilities, NSError *error){
if (error != nil) {
// Handle error.
} else if (capabilities & SKCloudServiceCapabilityMusicCatalogPlayback) {
// CASE WHERE USER HAS APPLE MUSIC SUBSCRIPTION
// GET USER TOKEN HERE
}
}];