Skip to main content

How To Set App Update Alert In IOS App in Objective C

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 ([lookup[@"resultCount"] integerValue] == 1)
                 {
                     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

Popular Posts

What are the Alternatives of device UDID in iOS? - iOS7 / iOS 6 / iOS 5 – Get Device Unique Identifier UDID

Get Device Unique Identifier UDID Following code will help you to get the unique-device-identifier known as UDID. No matter what iOS user is using, you can get the UDID of the current iOS device by following code. - ( NSString *)UDID { NSString *uuidString = nil ; // get os version NSUInteger currentOSVersion = [[[[[UIDevice currentDevice ] systemVersion ] componentsSeparatedByString: @" . " ] objectAtIndex: 0 ] integerValue ]; if (currentOSVersion <= 5 ) { if ([[ NSUserDefaults standardUserDefaults ] valueForKey: @" udid " ]) { uuidString = [[ NSUserDefaults standardDefaults ] valueForKey: @" udid " ]; } else { CFUUIDRef uuidRef = CFUUIDCreate ( kCFAllocatorDefault ); uuidString = ( NSString *) CFBridgingRelease ( CFUUIDCreateString ( NULL ,uuidRef)); CFRelease (uuidRef); [[ NSUserDefaults standardUserDefaults ] setObject: uuidString ForKey: @" udid " ]; [[ NSUserDefaults standardUserDefaults ] synchro...

An introduction to Size Classes for Xcode 8

Introduction to Size Classes for Xcode In iOS 8, Apple introduced  size classes , a way to describe any device in any orientation. Size classes rely heavily on auto layout. Until iOS 8, you could escape auto layout. IN iOS8, Apple changed several UIKit classes to depend on size classes. Modal views, popovers, split views, and image assets directly use size classes to determine how to display an image. Identical code to present a popover on an iPad  causes a iPhone to present a modal view. Different Size Classes There are two sizes for size classes:  compact , and  regular . Sometime you’ll hear about any.  Any  is the generic size that works with anything. The default Xcode layout, is  width:any height:any . This layout is for all cases. The Horizontal and vertical dimensions are called  traits , and can be accessed in code from an instance of  UITraitCollection . The  compact  size descr...

Master Map & Filter, Javascript’s Most Powerful Array Functions

Master Map & Filter, Javascript’s Most Powerful Array Functions Learn how Array.map and Array.filter work by writing them yourself This article is for those who have written a  for  loop before, but don’t quite understand how  Array.map  or  Array.filter  work. You should also be able to write a basic function. By the end of this, you’ll have a complete understanding of both functions, because you’ll have seen how they’re written. Array.map Array.map  is meant to transform one array into another by performing some operation on each of its values. The original array is left untouched and the function returns a new, transformed array. For example, say we have an array of numbers and we want to  multiply each number by three . We also don’t want to change the original array. To do this without  Array.map , we can use a standard for-loop. for-loop var originalArr = [1, 2, 3, 4, 5]; var newArr = []; for(var i = 0; i < originalArr.length; i+...