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. So are there any resources out there or examples ? Thanks a million !
Asked
Active
Viewed 1,771 times
1 Answers
9
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
NSString *search = [originalSearch stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
Then, just request the JSON data like this:
[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!

JomanJi
- 1,407
- 1
- 17
- 27
-
Any chance you could convert this to Swift? I am having a very hard time using the sound cloud api with my swift application – Will Jamieson Dec 29 '14 at 21:38
-
@Will Jamieson I'm not really using swift, but I'll try! – JomanJi Dec 30 '14 at 07:11
-
That would be awesome. I currently just resorted to making HTTP Get requests and ignoring the wrapper sdk – Will Jamieson Dec 30 '14 at 14:53