Error Occurred when requesting user token (SKErrorDomain Code=7)

Trying to get the sample project to work (Adding Content to Apple Music). I've gotten a proper developer token and I can log in and see that I'm authorized by MPMediaLibrary and SKCloudServiceController. I also have both "Add to Cloud Music Library" and "Music Catalog Playback" capabilities.


When I try to return music data by clicking on the "Recents" tab, I get the error:


"No User Token was Specified. Request Authorization using the Authorization tab." I already have authorization in that tab as noted above.


From debugging, this is the code that errors out.


if SKCloudServiceController.authorizationStatus() == .authorized {

let completionHandler: (String?, Error?) -> Void = { [weak self] (token, error) in

guard error == nil else {

print("An error occurred when requesting user token: \(error!.localizedDescription)")

return

}


error.localizedDescription is SKErrorDomain Code = 7. From my searches, this seems to be a can't connect to the cloud error? Though I can't confirm that..


Any idea why I would show SKCloudService authorized in one tab but yet it still seems to error out?


Thanks for the help,

Replies

I figure out this Error. The code 7 it is because your generate a long expire time for your developer token.Try make is less 3 days.

True. I get the eror as soon as I try to set the expiration > 179 days!

It doesn't work for me.

Developer token works fine. (tested using REST API)

But I'm not enable to obtain user token.

Hello guys, I was having this same problem and I solved it.


I installed the iTunes Store App in the phone and now is fetching my user Token, also I initialized my cloudServiceController after the request authorization and not in the declaration of the variable.



SKCloudServiceController.requestAuthorization { [weak self] (authorizationStatus) in

switch authorizationStatus {

case .authorized:

print("Authorized")

self?.cloudServiceController = SKCloudServiceController()

self?.requestCloudServiceCapabilities()

self?.cloudServiceController?.requestUserToken(forDeveloperToken: MusicLibrary.libraryToken, completionHandler: self!.trytest)

default:

break

}

Code:

func fetchUserToken(developerToken : String, result: @escaping FlutterResult) {
print("iOS Developer Token", developerToken)
if #available(iOS 11.0, *) {
// let serviceController = SKCloudServiceController()
if SKCloudServiceController.authorizationStatus() == .authorized {
SKCloudServiceController().requestUserToken(forDeveloperToken: developerToken) { (userToken, err) in
if (err != nil) {
result(FlutterError(code: FlutterErrorCode.unavailable, message: "Error Encountered", details: err.debugDescription))
print("iOS fetchUserToken", err.debugDescription)
} else {
result(userToken)
}
}
}
}
else {
result(FlutterError(code: FlutterErrorCode.unavailable, message: "Not supported on iOS < 9.3", details: nil))
}
}

Error Log:

2019-02-01 13:56:16.576496+0530 Runner[327:12914] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""
2019-02-01 13:56:16.576616+0530 Runner[327:12914] SSAccountStore: Failed to fetch the backing accounts. error = Error Domain=com.apple.accounts Code=9 "(null)"
2019-02-01 13:56:16.578046+0530 Runner[327:13193] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""
2019-02-01 13:56:16.578133+0530 Runner[327:13193] SSAccountStore: Failed to fetch the backing accounts. error = Error Domain=com.apple.accounts Code=9 "(null)"
2019-02-01 13:56:16.581226+0530 Runner[327:13193] SSAccountStore: Unable to get the local account. error = Error Domain=SSErrorDomain Code=100 "Cannot connect to iTunes Store" UserInfo={NSLocalizedDescription=Cannot connect to iTunes Store}
iOS fetchUserToken Optional(Error Domain=SKErrorDomain Code=7 "(null)" UserInfo={NSUnderlyingError=0x28113c690 {Error Domain=SSErrorDomain Code=109 "(null)" UserInfo={NSUnderlyingError=0x28113c720 {Error Domain=SSErrorDomain Code=109 "Cannot connect to iTunes Store" UserInfo={NSLocalizedDescription=Cannot connect to iTunes Store, SSErrorHTTPStatusCodeKey=401}}}}})


I am seeing this error once more, I validated the developer token, appId etc. double checked the developer token process.

Also this code seemd to work well a few days ago.


Please Advise.

I am seeing the exact same messages. The code 9 and cannot connect to Itunes store messages seem to be something new, I only started seeing them around early this year, did not see them before that. The code 7 user token seems to be independent of those and showed up for when I got a new developer token and had to generate a new user token. Huang Jobs suggestion worked for me, it went away when I changed the expiry to 3 days. Try setting your Developer token expiry to <= 3 days. if that works, see what maximum value works for you.

I still see the code 9 and cannot connect to Itunes store messages, but my app is working fine.