Announcements

Help Wizard

Step 1

NEXT STEP

iOS SDK - Authorization fails only when Spotify app is installed

Solved!

iOS SDK - Authorization fails only when Spotify app is installed

Link to original issue post on Github: https://github.com/spotify/ios-sdk/issues/183

 

Hi everyone, I have spent many hours now and have still not been able to resolve this issue I had several months ago with the iOS SDK. Another user on Github had the same issue, so I'm hoping someone on these boards will have an idea.

 

I'm using the Authorization code flow, but when I call initiateSession and am redirected to the Spotify app, I see the "authorizing ..." pop-up but then when it finishes I get an "X" rather than the usual checkmark and am redirected back to my app. No sessionManager delegate function (didFailWith, for example) is called and my app just hangs.

Of note:

  • if I uninstall Spotify and use the web view authorization to authorize, rather than SFAuthenticationSession, I authorize just fine.
  • I cannot force this by setting sessionManager.alwaysShowAuthorizationDialog = true, it still just flips to Spotify and starts "authorizing ..." (and then fails) regardless
  • running the code in the XCode simulator works.
  • as of today where latest iOS is 13.2, my issue is occurring on devices running both iOS 13.1.3 and 12.1.3
  • I recently lowered the deployment target for my app to iOS 12.0, around then is when I started seeing issues

The only workaround that I have found so far is to remove Spotify from LSApplicationsQueriesScheme in my info.plist. This forces my app to use the web view authorization flow. Obviously this is slower and much worse UX than an automatic authorization using SFAuthentificationSession.

Does anyone know why this might be happening? I also don't know how to get logs from the call to sessionManager.initiateSession so any help with that would also be greatly appreciated

Reply

Accepted Solutions
Marked as solution

Hope it would help you.

A. no dialog:

You forget one thing in AppDelegate.swift. Add the code to process the response from spotify. After this process , delegate of sessionManager will be called.
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
rootViewController.sessionManager.application(app, open: url, options: options)
return true
}
But after ios 13, it wouldn't call thie func above.You need to do as follow.
1. Add openURLContexts func in SceneDelegate file to process the same thing of openURL in appdelegate.
- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
UIOpenURLContext *ctx = [URLContexts allObjects][0];
ViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
[rootVC.sessionManager application:[UIApplication sharedApplication] openURL:ctx.URL options:ctx.options];
}
2. remove UISceneConfigurations section from info.plist. Then it will callback to openurl.

 

B.authorization error. Check below.

Something to do: 

1.DASHBORAD: 

add bound id;

redirecturl;

2.APP:

add LSApplicationQueriesSchemes;

add URL Types:

3.rb script:

change your client id;

cahnge your redirecturl;

View solution in original post

3 Replies
Marked as solution

Hope it would help you.

A. no dialog:

You forget one thing in AppDelegate.swift. Add the code to process the response from spotify. After this process , delegate of sessionManager will be called.
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
rootViewController.sessionManager.application(app, open: url, options: options)
return true
}
But after ios 13, it wouldn't call thie func above.You need to do as follow.
1. Add openURLContexts func in SceneDelegate file to process the same thing of openURL in appdelegate.
- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
UIOpenURLContext *ctx = [URLContexts allObjects][0];
ViewController *rootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
[rootVC.sessionManager application:[UIApplication sharedApplication] openURL:ctx.URL options:ctx.options];
}
2. remove UISceneConfigurations section from info.plist. Then it will callback to openurl.

 

B.authorization error. Check below.

Something to do: 

1.DASHBORAD: 

add bound id;

redirecturl;

2.APP:

add LSApplicationQueriesSchemes;

add URL Types:

3.rb script:

change your client id;

cahnge your redirecturl;

Hi Ouml,
Thanks so much for your help. With your suggestions, I figured out the problem was that the Bundle ID I had listed in my Spotify Dashboard settings was antiquated and no longer was the same as the bundle ID in my XCode project. In my Info.plist, I was using the CFBundleURLName of the XCode project, not what was in the dashboard, so I added my XCode bundle ID to my Spotify project dashboard, and now it is working again. Thanks again!

glad to help you.

Suggested posts