SSAccountStore: Unable to get the local account. error = Error Domain=SSErrorDomain Code=100
Asked Answered
P

2

7

I am having trouble getting access to the users Apple Music. The error I am getting is

 [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""
2019-02-04 19:14:37.250467+0900 SSAccountStore: Failed to fetch the backing accounts. error = Error Domain=com.apple.accounts Code=9 "(null)"
2019-02-04 19:14:37.252008+0900 [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""
2019-02-04 19:14:37.252051+0900  SSAccountStore: Failed to fetch the backing accounts. error = Error Domain=com.apple.accounts Code=9 "(null)"
2019-02-04 19:14:37.253604+0900  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}

However the weird part of this code is that I am also able to retrieve the Music User Token. Is there sth that I am missing? Any help is appreciated.

    static func auth(){
        let cloudServiceController = SKCloudServiceController()

        let developerToken = "abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyz"


        SKCloudServiceController.requestAuthorization { status in
            guard status == .authorized else { return }
        }

        cloudServiceController.requestCapabilities { capabilities, error in
            guard capabilities.contains(.musicCatalogPlayback) else { return }
        }

        cloudServiceController.requestUserToken(forDeveloperToken: developerToken, completionHandler: { token, error in

            guard let token = token else { return }
            UserDefaults.standard.set(token, forKey: "MUSIC_USER_TOKEN")
            UserDefaults.standard.set(developerToken, forKey: "DEVELOPER_TOKEN")
            print("Music User Token:", token)
        })
    }
Poppy answered 4/2, 2019 at 10:26 Comment(2)
Did you resolve your issue? I'm struggling with the same error right now..Sulphone
I get the same errors. Do you happen to have different AppleIds for the iCloud and iTunesStore? I do and wonder if it may be because of that...Osullivan
V
0

I think you have to call cloudServiceController.requestUserToken once user has authorised after completion handler for SKCloudServiceController.requestAuthorization

Vange answered 16/12, 2019 at 7:33 Comment(1)
OP would be getting a different error if SKCloudServiceController.requestAuthorization.requestAuthorization is failing. That error is this: Error Domain=SKErrorDomain Code=6 "The requesting app does not have the necessary permissions" UserInfo={NSLocalizedDescription=The requesting app does not have the necessary permissions}. So this isn't the issue. (Although I agree OP's given code isn't organizing the callbacks' executions correctly)Manifestation
M
0

I was having this same issue until I removed Bearer from the beginning of developerToken.

OP's code example has developerToken set to "abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyz", so I can only assume if OP is including Bearer at the beginning or not.

So to be more clear, this is what I was doing before:

asyncAskMyServerToGenerateMyAppleMusicDeveloperJWTDevToken { rawDevToken in
    let formattedDeveloperToken = "Bearer \(rawDevToken)"
    SKCloudServiceController().requestUserToken(forDeveloperToken: formattedDeveloperToken)
    { possibleToken, _ in
        if let userMusicToken = possibleToken
        {
            YayIGotIt.forTheWin(userMusicToken)
        }
    }
}

And this is what I did to make it actually work:

asyncAskMyServerToGenerateMyAppleMusicDeveloperJWTDevToken { rawDevToken in

    //Not prepending "Bearer " anymore
    SKCloudServiceController().requestUserToken(forDeveloperToken: rawDevToken)
    { possibleToken, _ in
        if let userMusicToken = possibleToken
        {
            YayIGotIt.forTheWin(userMusicToken) //This actually fires now
        }
    }
}
Manifestation answered 23/12, 2019 at 23:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.