Swift上的SoundCloud SDK,无法翻译

时间:2015-03-22 09:34:46

标签: ios objective-c swift sdk soundcloud

我需要将SoundCloud SDK用于Swift。有人有经验吗? 即使在集成指南开始时我也遇到了问题:https://developers.soundcloud.com/docs/api/ios-quickstart#authentication

在AppDelegate中,当我写

var scurl: NSURL
scUrl = NSURL(string: "www.francescocrema.it")!
SCSoundCloud.setClientID(idCode,secret: secCode, redirectURL: scUrl)

当它被执行时,应用程序崩溃了SIGABRT并且没有可见的错误! 另外,我无法将此代码转换为Swift

- (IBAction) login:(id) sender
{
SCLoginViewControllerCompletionHandler handler = ^(NSError *error) {
    if (SC_CANCELED(error)) {
        NSLog(@"Canceled!");
    } else if (error) {
        NSLog(@"Error: %@", [error localizedDescription]);
    } else {
        NSLog(@"Done!");
    }
};

[SCSoundCloud requestAccessWithPreparedAuthorizationURLHandler:^(NSURL *preparedURL) {
    SCLoginViewController *loginViewController;

    loginViewController = [SCLoginViewController
                           loginViewControllerWithPreparedURL:preparedURL
                                            completionHandler:handler];
    [self presentModalViewController:loginViewController animated:YES];
}];
}

有人了解更多有关SoundCloud API的信息吗? 你能帮帮我吗?

2 个答案:

答案 0 :(得分:0)

我担心SoundCloud API不再由其团队维护。我建议你使用自己的库。我也在使用SoundCloud API,所以我决定创建一个,也许它对你有用。

ABMSoundCloudAPI on Github

答案 1 :(得分:0)

您的redirectURL无效。 SCRequest要求使用方案https的URL:

NSAssert1([[aResource scheme] isEqualToString:@"https"], @"Resource '%@' is invalid because the scheme is not 'https'.", aResource);

您的Swift演示代码可能看起来像这样:

SCSoundCloud.requestAccess { (url) in
    let loginViewController = SCLoginViewController(preparedURL: preparedUrl, completionHandler: nil)
    self.present(loginViewController, animated: true)
}