2017-05-10 1 views
1

私はspotify-iOS-SDKを使用してアプリケーションを開発していますが、Spotify AppからSpotifyに接続すると成功しました。それは、Spotifyにチェックマークアイコンが表示された後に私のアプリに戻ってきて、セッションがnullであるためにアプリにクラッシュを引き起こしました。iOS: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は、アクションを入れています。私はここで間違って何をしていますか?私はDemoProjectをhttps://github.com/spotify/ios-sdk から見て、うまくいきました。私のアプリは、Spotifyはアプリケーションに

+0

あなたの 'AppUelegate'に' openURL'のコードはありますか? –

答えて

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 


} 
+0

それは問題ではない、私は私のAppDelegateにそのハンドラを入れて、実際の問題は私のアプリで私のbundleIDとSpotifyDashboardは異なる:) –

関連する問題