简体   繁体   English

如何使用soundcloud Sdk iOS搜索曲目

[英]How to search for tracks using the soundcloud Sdk iOS

I have read the soundcloud's sdk documentation for iOS and it doesn't seem to say anything about searching for songs, though it talked about listing tracks from an existing soundcloud user. 我已经阅读了适用于iOS的soundcloud的sdk文档,但它似乎没有说到搜索歌曲的任何内容,尽管它谈到了从现有的soundcloud用户列出曲目。 So are there any resources out there or examples ? 那么有没有资源或示例? Thanks a million ! 太感谢了 !

You have to use this format: 你必须使用这种格式:

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

Just remember, if the user enters a space, you have to replace it with %20 , you can achieve this by 请记住,如果用户输入空格,则必须将其替换为%20 ,您可以实现此目的

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

Then, just request the JSON data like this: 然后,只需要像这样请求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) {

My final code looks like this: 我的最终代码如下所示:

 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);

    }

}];`

I hope this helped! 我希望这有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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