SSAccountStore:无法获取本地帐户。错误=错误域= SSErrorDomain代码= 100

时间:2019-02-04 10:26:33

标签: swift apple-musickit

我无法访问用户Apple Music。 我收到的错误是

 [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}

但是,这段代码的怪异之处在于,我还能够检索“音乐用户令牌”。 我有什么想念的吗? 任何帮助表示赞赏。

    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)
        })
    }

2 个答案:

答案 0 :(得分:0)

我认为你必须打电话 cloudServiceController.requestUserToken 一旦用户为SKCloudServiceController.requestAuthorization

的完成处理程序授权后

答案 1 :(得分:0)

直到从Bearer的开头删除developerToken以来,我一直遇到同样的问题。

OP的代码示例将developerToken设置为"abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyz",所以我只能假设OP开头是否包含Bearer。

更清楚地说,这是我之前所做的:

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

这就是我所做的,以使其真正起作用:

asyncAskMyServerToGenerateMyAppleMusicDeveloperJWTDevToken { rawDevToken in

    //Not prepending "Bearer " anymore
    SKCloudServiceController().requestUserToken(forDeveloperToken: rawDevToken)
    { possibleToken, _ in
        if let userMusicToken = possibleToken
        {
            YayIGotIt.forTheWin(userMusicToken) //This actually fires now
        }
    }
}