Skip to content

Instantly share code, notes, and snippets.

@Gurpartap
Created August 7, 2011 04:56
Show Gist options
  • Save Gurpartap/1130060 to your computer and use it in GitHub Desktop.
Save Gurpartap/1130060 to your computer and use it in GitHub Desktop.
Process the result of server side app version check
- (void)request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data {
NSString *dataString = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
if ([dataString length] > 0) {
self.manifest = [NSDictionary dictionaryWithDictionary:[dataString JSONValue]];
if ([[_manifest objectForKey:@"needsUpdate"] boolValue] == YES && [self remindNow] == YES) {
NSString *alertTitle = NSLocalizedString(@"Update available", nil);
if ([[_manifest allKeys] containsObject:@"alertTitle"]) {
alertTitle = [_manifest objectForKey:@"alertTitle"];
}
NSString *alertMessage = NSLocalizedString(@"v%@ update is now available on the App Store.", nil);
alertMessage = [alertMessage stringByAppendingFormat:@"\n\n%@\n\n%@", NSLocalizedString(@"You are currently using v%@.", nil), NSLocalizedString(@"Please update to the latest version.", nil)];
if ([[_manifest allKeys] containsObject:@"alertMessage"]) {
alertMessage = [_manifest objectForKey:@"alertMessage"];
}
NSString *latestVersion = [_manifest objectForKey:@"latestVersion"];
NSString *bundleVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:alertTitle
message:[NSString stringWithFormat:alertMessage, latestVersion, bundleVersion]
delegate:self
cancelButtonTitle:NSLocalizedString(@"Remind later", nil)
otherButtonTitles:NSLocalizedString(@"Get update", nil), nil] autorelease];
[alert show];
}
}
self.manifestRequest = nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment