简体   繁体   中英

SoundCloud SDK on Swift, can't translate

I need to use SoundCloud SDK into a Swift. Does someone have experience in this? I have problem even at the start of their integration guide: https://developers.soundcloud.com/docs/api/ios-quickstart#authentication

When, in AppDelegate, I write

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

when it gets executed, the app crashed with SIGABRT and no visible error! Plus, I can't manage to translate this code to 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];
}];
}

Does someone know more about SoundCloud API? Could you help me?

I am afraid SoundCloud API is not longer maintain by its team. I would recommend you to use your own library. I am using SoundCloud API as well so I decided to create one, maybe it can be useful for you.

ABMSoundCloudAPI on Github

Your redirectURL is invalid. SCRequest requires a URL with the scheme https :

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

Your Swift presentation code might look like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM