0
votes

Here is my code to get user token

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

        }];
    }];

but I am getting userToken as nil and error as

"Error Domain=SKErrorDomain Code=7 "(null)" UserInfo={NSUnderlyingError=0x1c08437b0 {Error Domain=SSErrorDomain Code=109 "(null)" UserInfo={NSUnderlyingError=0x1c08437e0 {Error Domain=SSErrorDomain Code=109 "Cannot connect to iTunes Store" UserInfo={NSLocalizedDescription=Cannot connect to iTunes Store, SSErrorHTTPStatusCodeKey=401}}}}}"

What I'm doing wrong ? please help

2
Same problem for me, with valid developer token. Did you find a solution?Florent Morin
nope, nothing yetNew Coder
Did you find any solution?Aditya Ahuja

2 Answers

1
votes

For me personally, the issue was not having an Apple Music subscription; I had the same error ("Error Domain=SKErrorDomain Code=7").

One way to get around this is to check if the user has an Apple Music account. To do this (by way of the Apple documentation)

Swift:

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
    }
}];
0
votes

The error code SSErrorHTTPStatusCodeKey=401 typically means it is an unauthorized request, which indicates to me that your developer token is invalid. Are you sure that is a correctly formatted, non-expired developer token?