App Update Alert In IOS App in Objective C
The app update alert must be set an your AppDelegate.m file in your didFinishLaunchingWithOptions method.
- (void)requestUpdate {
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *appID = infoDictionary[@"CFBundleIdentifier"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?bundleId=%@",appID]];
NSData *data = [NSData dataWithContentsOfURL:url];
if (data != nil) {
NSDictionary *lookup = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if (data != nil) {
NSDictionary *lookup = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if ([lookup[@"resultCount"] integerValue] == 1)
{
NSString *appStoreVersion = lookup[@"results"][0][@"version"];
NSString *currentVersion = infoDictionary[@"CFBundleShortVersionString"];
{
NSString *appStoreVersion = lookup[@"results"][0][@"version"];
NSString *currentVersion = infoDictionary[@"CFBundleShortVersionString"];
if (![appStoreVersion isEqualToString:currentVersion])
{
appURL = lookup[@"results"][0][@"trackViewUrl"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"App Update Available" message:@"" delegate:self cancelButtonTitle:@"Update Now" otherButtonTitles:@"Remind me later", nil];
alert.tag=22;
[alert show];
}
}
}
}
Next, you mast set a <UIAlertViewDelegate> in your file.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 22) {
if (buttonIndex == 0) {
// you can throw to direct AppStore to update the app.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appURL]];
} else if (buttonIndex == 1) {
NSLog(@"Skip Update");
}
}
}
Comments
Post a Comment
Thank You.