Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store JSON iTunes Search API data

How can I use the iTunes search API from within iOS/Obj-c ?

I know of this link of course..

http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html

I just don't understand how you use obj-c/iOS with it.

I want to be able to read the JSON results, whether they be broad or just 1 result and store the apps name (or would that be ID?), any images, rating etc in my server database (using parse.com).

How can I do that, and is that allowed by the Apple developer terms?

like image 246
Phil Avatar asked Dec 27 '22 13:12

Phil


1 Answers

It looks like you just make the requests and parse the results. No auth or anything else fancy...

NSString *urlString = @"https://itunes.apple.com/search?term=jack+johnson";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request
                                   queue:[NSOperationQueue mainQueue]
                       completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                           if (!error) {
                               NSError* parseError;
                               id parse = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&parseError];
                               NSLog(@"%@", parse);
                           }
                       }];

The JSON parser will yield arrays of dictionaries for collection calls and (probably) dictionaries for single objects.

like image 179
danh Avatar answered Jan 09 '23 09:01

danh