[英]How to search for tracks using the soundcloud Sdk iOS
我已经阅读了适用于iOS的soundcloud的sdk文档,但它似乎没有说到搜索歌曲的任何内容,尽管它谈到了从现有的soundcloud用户列出曲目。 那么有没有资源或示例? 太感谢了 !
你必须使用这种格式:
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) {
我的最终代码如下所示:
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);
}
}];`
我希望这有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.