Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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:@"", 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"];
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];

This comment has been minimized.

Copy link

commented Aug 10, 2014

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
You can’t perform that action at this time.