1

I am new in iOS and I am facing problem regarding to check new update available to Apple Store.

Is there is any API to check?

Andriy
  • 2,767
  • 2
  • 21
  • 29
Muju
  • 884
  • 20
  • 54

2 Answers2

5

do like

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.

// Fabric implementation

[self needsUpdate:^(NSDictionary *dictionary) {
    // you can use the dictionary here

     NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];

    if ([dictionary[@"resultCount"] integerValue] == 1){
        NSString* appStoreVersion = dictionary[@"results"][0][@"version"];
        NSString* currentVersion = infoDictionary[@"CFBundleShortVersionString"];
        if (![appStoreVersion isEqualToString:currentVersion]){
            NSLog(@"Need to update [%@ != %@]", appStoreVersion, currentVersion);
             [self showAlert];
        }


    }

    // if you want to update UI or model, dispatch this to the main queue:
   // dispatch_async(dispatch_get_main_queue(), {
        // do your UI stuff here
    //    do nothing
   // });
}];

}

for reference purpose I taken the answer from here

-(void)needsUpdate:(void (^)(NSDictionary * dictionary))completionHandler{

NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString* appID = infoDictionary[@"CFBundleIdentifier"];
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?bundleId=%@", appID]];
   NSURLRequest *request = [NSURLRequest requestWithURL:url];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
                                        completionHandler:
                              ^(NSData *data, NSURLResponse *response, NSError *error) {

                                  NSDictionary* lookup = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

                                  if (completionHandler) {
                                      completionHandler(lookup);
                                  }



                              }];

[task resume];



}

show the alert

-(void)showAlert
{
UIAlertController *alertController = [UIAlertController  alertControllerWithTitle:@"please update app"  message:nil  preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"Okay!" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
                            {
                                @try
                                {
                                    NSLog(@"tapped ok");
                                    BOOL canOpenSettings = (UIApplicationOpenSettingsURLString != NULL);
                                    if (canOpenSettings)
                                    {
                                        NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com/in/app/tvfplay/id1067732674?mt=8"];
                                        [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
                                    }
                                }
                                @catch (NSException *exception)
                                {

                                }
                            }]];
UIWindow* topWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
topWindow.rootViewController = [UIViewController new];
topWindow.windowLevel = UIWindowLevelAlert + 1;
[topWindow makeKeyAndVisible];
[topWindow.rootViewController presentViewController:alertController animated:YES completion:nil];

}
Community
  • 1
  • 1
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
  • 1
    This is a bad solution. dataWithContentsOfURL: will block your app until it has retrieved the data. So over a mobile connection or bad connection, your app could be unresponsive for a minute or more until it has finished downloading the data. You should really download this information asynchronously using NSURLSession. – uliwitness Mar 03 '17 at 10:15
  • @Anbu.Karthik Can I used this code in ViewDidLoad() After login. – Muju Mar 03 '17 at 10:29
  • @Muju - choice is urs , where u need you can apply – Anbu.Karthik Mar 03 '17 at 10:33
  • @Anbu.Karthik Your code is forcing user to update. I just need to check version and show just simple popup for update. – Muju Mar 03 '17 at 11:01
  • @Muju - concept is common, based on your choice we can show, simple in UIalertController add `Cancel` button, it is optional to update if user willing to update else do nothing – Anbu.Karthik Mar 03 '17 at 11:05
  • @Anbu.Karthik It is Showing black screen after click on cancel. – Muju Mar 03 '17 at 11:09
  • where you added the UIaertcontroller in VC or appdelegate – Anbu.Karthik Mar 03 '17 at 11:13
  • @Muju - happy to hear – Anbu.Karthik Mar 03 '17 at 13:16
  • @Anbu.Karthik Can you please check this question and answer it http://stackoverflow.com/questions/43539307/how-to-post-string-with-special-character-and-thai-language-using-xml-parsing-in. – Muju Apr 22 '17 at 06:33
1

There is no direct API available for app update checking but you can check current version to iTune version.

Please check below links for the same :

SO Answer's:

IOS app update check within application

Check if my app has a new version on AppStore

There is also one library for checking update :

https://github.com/nicklockwood/iVersion

Hope this will helps you to check your app update.

Community
  • 1
  • 1
CodeChanger
  • 7,953
  • 5
  • 49
  • 80