Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Check if new version of app is present in appstore programmatically.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 3.79k
    Comment on it

    Many apps these days show an alert on app's launch saying a new update is present at the store.

    To implement this feature first we need to find version of the app available on app store and version of the current running app and then compare both of them.

     

    Here's how to do it :

     

    + (BOOL)newVersionPresent {
        
        // 1. Get bundle identifier
        NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
        NSString* appID = infoDict[@"CFBundleIdentifier"];
        
        // 2. Find version of app present at itunes store
        NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?bundleId=%@", appID]];
        NSData* data = [NSData dataWithContentsOfURL:url];
        NSDictionary* itunesVersionInfo = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
        
        // if app present
        if ([itunesVersionInfo[@"resultCount"] integerValue] == 1){
            NSString* appStoreVersion = itunesVersionInfo[@"results"][0][@"version"];
    
            // 3. Find version of app currently running
            NSString* currentVersion = infoDictionary[@"CFBundleShortVersionString"];
    
            // 4. Compare both versions
            if ([appStoreVersion compare:currentVersion options:NSNumericSearch] == NSOrderedDescending) {
                // app needs to be updated
                return YES;
            }
        }
        return NO;
    }

     

    #warning: The lookup by bundleId works fine but is not in apple's documentation. So apple could change it without notice. Read this for more info.

     

    Once found that a new version of the app is present at the app store we can also give user the option to go to the version of the app at the appstore. Following code snippet does this for us:

     

    +(void)goToAppStore {
        static NSString *const iOSAppStoreURLFormat = @"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@";
        NSURL *appStoreLink = [NSURL URLWithString:[NSString stringWithFormat:iOSAppStoreURLFormat, APP_STORE_ID]];
        [[UIApplication sharedApplication] openURL:appStoreLink];   
    }

    Where APP_STORE_ID is the app Id of your app. This can be found by following these steps:

    1. Open iTunes
    2. Search for your app
    3. Click/RightClick on app's name and copy URL

    The URL is in following format: http://itunes.apple.com/[country]/app/[App–Name]/id[App Id or Store Id]?mt=8

    The App Id or Store Id is our required id.

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: