iOS:无法从Spotify应用程序请求授权

时间:2017-05-10 05:19:50

标签: iphone swift3 ios10 spotify

我使用spotify-iOS-SDK开发应用程序,我已成功将我的应用程序从Safari连接到Spotify,但是当我尝试从Spotify App连接我的应用程序时,它不会在spotify中请求授权应用程序,然后它在Spotify中显示一个复选标记图标后将我带回我的应用程序,它导致我的应用程序崩溃,因为会话为空。

这是我的代码:

var auth = SPTAuth.defaultInstance()!
auth.redirectURL     = URL(string: ENV.SPOTIFY_REDIRECT_URL
auth.clientID        = ENV.SPOTIFY_CLIENT_ID
auth.requestedScopes = [SPTAuthStreamingScope, SPTAuthPlaylistReadPrivateScope, 
    SPTAuthPlaylistModifyPublicScope, SPTAuthPlaylistModifyPrivateScope]

    if SPTAuth.supportsApplicationAuthentication(){
        UIApplication.shared.openURL(auth.spotifyAppAuthenticationURL())
    }else{
        if UIApplication.shared.openURL(auth.spotifyWebAuthenticationURL()){
            if auth.canHandle(auth.redirectURL) {
                // To do - build in error handling

            }
        }

    }

我在我的LSApplicationQueriesSchemes中添加了spotify-action。我在这做错了什么?我从https://github.com/spotify/ios-sdk看到了DemoProject 它起作用了。它应该在我的应用程序转到Spotify App后立即请求授权

2 个答案:

答案 0 :(得分:0)

您的AppDelegate中需要一些代码如下:

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        let auth = SPTAuth()
        if auth.canHandle(auth.redirectURL) {
            auth.handleAuthCallback(withTriggeredAuthURL: url, callback: { (error, session) in
            // Do other things to save session...
            return true
        }

        return false


}

答案 1 :(得分:0)

我已经解决了我的问题,问题是我的应用程序中的Bundle ID与我的Spotify Dashboard中的BundleID不同。 https://developer.spotify.com/my-applications

只需匹配我的捆绑包ID就可以了!

相关问题