如何使用soundcloud Sdk iOS搜索曲目

ipa*_*yte 8 api sdk objective-c ios soundcloud

我已经阅读了适用于iOS的soundcloud的sdk文档,但它似乎没有说到搜索歌曲的任何内容,尽管它谈到了从现有的soundcloud用户列出曲目.那么有没有资源或示例?太感谢了 !

Jom*_*nJi 9

你必须使用这种格式:

https://api.soundcloud.com/me/tracks?q=SEARCHTEXT&format=json

请记住,如果用户输入空格,您必须更换它%20,您可以实现此目的

NSString *search = [originalSearch stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

然后,只需要像这样请求JSON数据:

[SCRequest performMethod:SCRequestMethodGET onResource:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.soundcloud.com/me/tracks?q=%@&format=json", search]] usingParameters:nil withAccount:[SCSoundCloud account] sendingProgressHandler:nil responseHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
Run Code Online (Sandbox Code Playgroud)

我的最终代码如下所示:

 NSString *search = [searchBar.text stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

[SCRequest performMethod:SCRequestMethodGET onResource:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.soundcloud.com/me/tracks?q=%@&format=json", search]] usingParameters:nil withAccount:[SCSoundCloud account] sendingProgressHandler:nil responseHandler:^(NSURLResponse *response, NSData *data, NSError *error) {

    NSError *jsonError;
    NSJSONSerialization *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];

    if (!jsonError && [jsonResponse isKindOfClass:[NSArray class]]) {

        self.searchQuery = (NSArray *)jsonResponse;
        [self.tableView reloadData];

    }

    else {

        NSLog(@"%@", error.localizedDescription);

    }

}];`
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助!