【发布时间】:2014-04-30 06:55:51
【问题描述】:
我只是在开发基于 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 看起来是正确的。
【问题讨论】:
标签: ios web-applications cordova sdk spotify