Can I force an iPhone user to upgrade an application?

Is it possible to force the user to upgrade once there is a new version of my application available in the iTunes Store?

I am presently working on an application. However, I want to force the upgrade whenever I upload a newer version, because the upgrade will have more features and I want to discard the previous version. Is this possible by default with iPhone or do I have to write my own implementation to check the current version and compare it to the store?


Solution 1:

I have done this feature by getting version from itunes webservice and comparing with the current version.. Following is my code

        NSString *version = @"";
        NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/lookup?id=<Your app ID>"];
        versionRequest = [ASIFormDataRequest requestWithURL:url];
        [versionRequest setRequestMethod:@"GET"];
        [versionRequest setDelegate:self];
        [versionRequest setTimeOutSeconds:150];
        [versionRequest addRequestHeader:@"Content-Type" value:@"application/json"]; 
        [versionRequest startSynchronous];

        //Response string of our REST call
        NSString* jsonResponseString = [versionRequest responseString];

        NSDictionary *loginAuthenticationResponse = [jsonResponseString objectFromJSONString];

        NSArray *configData = [loginAuthenticationResponse valueForKey:@"results"];

        for (id config in configData) 
        {
            version = [config valueForKey:@"version"];
        }
   //Check your version with the version in app store
        if (![version isEqualToString:[itsUserDefaults objectForKey:@"version"]]) 
        {
            ProAlertView *createUserResponseAlert = [[ProAlertView alloc] initWithTitle:@"New Version!!" message: @"A new version of app is available to download" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: @"Download", nil];
        [createUserResponseAlert show]; 
        [createUserResponseAlert release];
        }

And put the app id in the itunes link see the code below..

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    // the user clicked one of the OK/Cancel buttons
    if (buttonIndex == 1)
    {
        NSString *iTunesLink = @"itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id=<appid>&mt=8";
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
    }
}

Note : You need JSONKit frame work and ASIHttp frame work to make the webservice calls..

Solution 2:

You can detect if the app needs an update then take some custom action like alert the user an update is available. Here is a code snippet that detects that an update is available.

-(BOOL) needsUpdate{
    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];
    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]){
            NSLog(@"Need to update [%@ != %@]", appStoreVersion, currentVersion);
            return YES;
        }
    }
    return NO;
}

Solution 3:

If you absolutely have to, you can launch the App Store so that your users can get the latest version from there. I would recommend making this optional, or at least presenting a dialogue first.

// iTunesLink should be your applications link
NSString *iTunesLink = @"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284417350&mt=8";


[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];

Solution 4:

This question was originally posted 7 years ago, and while some of the answers remain relevant, here is a more up-to-date approach.

I recommend https://github.com/ArtSabintsev/Siren which is Swift 3 compatible and can be installed with Cocoapods or Carthage.

CocoaPods, Swift 3 support:

pod 'Siren'

Carthage:

github "ArtSabintsev/Siren"

Solution 5:

The only way system handles updates of your application is prompting user that update is available in standard AppStore application.
Also, standalone application is not aware of available updates so you'll need to implement your web service where application can check if the current version is valid.
And I'm not sure if this conforms with Apple rules on applications, like (can't find proof-link though) you cannot upload trial versions for an application.

* EDIT * This answer is no longer true. See other upvoted answers for current truth.