Skip to content

Instantly share code, notes, and snippets.

@rupey
Created August 10, 2014 01:34
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rupey/f1429adab0877506c9fb to your computer and use it in GitHub Desktop.
Save rupey/f1429adab0877506c9fb to your computer and use it in GitHub Desktop.
iTunes Store API rating count retriever snippet
#pragma mark - iTunes Store API
#define ITUNES_APP_ID @"870393074"
- (void)updateReviewCount
{
NSString *countryCode = [[[NSLocale currentLocale] objectForKey: NSLocaleCountryCode] lowercaseString];
NSString *url = [NSString stringWithFormat:@"https://itunes.apple.com/%@/lookup?id=%@", countryCode, ITUNES_APP_ID];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
AFHTTPRequestOperation *req = [manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSDictionary *appInfo = [responseObject[@"results"] firstObject];
if (appInfo) {
NSInteger count = [appInfo[@"userRatingCountForCurrentVersion"] integerValue];
if (count > 0)
self.reviewCount = [NSString stringWithFormat:@"%ld %@ rated this version", (long)count, (count == 1) ? @"person has" : @"people have"];
else
self.reviewCount = @"Nobody has rated this version yet";
[self.tableView reloadData];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
self.reviewCount = @"Couldn't connect to App Store.";
[self.tableView reloadData];
}];
[req start];
}
@jeremytregunna
Copy link

On line 17, you should use %tu instead of %ld and a cast for the format specifier.

%tu works for NSUInteger
%tx for NSUInteger (hex output)
%zd for NSInteger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment