我已经阅读了适用于iOS的soundcloud sdk文档,虽然它谈到了从现有的soundcloud用户列出曲目,但它似乎没有说到搜索歌曲.那么有没有资源或示例?太感谢了 !
解决方法
你必须使用这种格式:
https://api.soundcloud.com/me/tracks?q=SEARCHTEXT\u0026amp;format=json
请记住,如果用户输入空格,您必须更换它,您可以实现此目的
Nsstring * search = [originalSearch stringByReplacingOccurrencesOfString:@“”withString:@“”];
然后,只需要像这样请求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",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);
}
}];`
我希望这有帮助!