Created
August 7, 2011 04:56
-
-
Save Gurpartap/1130060 to your computer and use it in GitHub Desktop.
Process the result of server side app version check
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
- (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