我只是在开发基于 Cordova 的 Web 应用程序,但我遇到了一个问题:我想在新应用程序中包含 Spotify。
Spotify 有初学者的 iOS SDK(测试版)Tutorial .效果很好(在应用程序加载时启动身份验证)。
现在我想在我的 WebApp 中使用 Cordova.exec();
实现它(不加载 - 我想在按钮单击时进行身份验证(由 JavaScript 触发)。
我为此生成了一个 Cordova 插件 - 可以正常工作。我可以通过 Cordova.exec();
触发方法。
此方法被触发:
- (BOOL)startSpotifyAuth:(CDVInvokedUrlCommand*)command {
// Create SPTAuth instance; create login URL and open it
NSURL *loginURL = [[SPTAuth defaultInstance] loginURLForClientId:kClientId declaredRedirectURL:[NSURL URLWithString:kCallbackURL] scopes:@[@"login"]];
// Opening a URL in Safari close to application launch may trigger an iOS bug, so we wait a bit before doing so.
// [UIApplication performSelector:@selector(openURL:) withObject:loginURL afterDelay:0.1];
NSLog(@"*** GOT THIS IN DEBUG CONSOLE ***");
// Ask SPTAuth if the URL given is a Spotify authentication callback
if ([[SPTAuth defaultInstance] canHandleURL:loginURL withDeclaredRedirectURL:[NSURL URLWithString:kCallbackURL]]) {
NSLog(@"*** GOT THIS - NOT - IN DEBUG CONSOLE ***");
// Call the token swap service to get a logged in session
[[SPTAuth defaultInstance] handleAuthCallbackWithTriggeredAuthURL:loginURL tokenSwapServiceEndpointAtURL:[NSURL URLWithString:kTokenSwapURL] callback:^(NSError *error, SPTSession *session)
{
if (error != nil) {
NSLog(@"*** Auth error: %@", error);
return;
}
// Call the -playUsingSession: method to play a track
[self playUsingSession:session];
}];
return YES;
}
return NO;
}
正如您在调试输出中看到的那样:我没有进入 if()。但我不知道为什么:loginURL 看起来是正确的。
最佳答案
您在 if 语句中使用了错误的 URL。此时,您需要验证在用户跳出到 Safari 进行身份验证后传递给您的应用程序的 URL,而不是您使用 SPAuth
生成的 URL。
关于ios - 带有 Spotify iOS SDK 的 Cordova iOS - 触发身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22583636/