7

我无法访问用户 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)
        })
    }
4

2 回答 2

0

我一直有同样的问题,直到我BearerdeveloperToken.

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
        }
    }
}
于 2019-12-23T23:18:08.150 回答
0

cloudServiceController.requestUserToken 我认为一旦用户在完成处理程序后授权,您就必须调用 SKCloudServiceController.requestAuthorization

于 2019-12-16T07:33:02.543 回答