Created
August 10, 2014 01:34
-
-
Save rupey/f1429adab0877506c9fb to your computer and use it in GitHub Desktop.
iTunes Store API rating count retriever snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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