Friday, 9 January 2015

force an iPhone user to upgrade an application





Get Version info Using Itunes web service 
   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:100]; [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"];
     }

 

Compare Both Versions  

NSString *version = @"1.0"; if (![version isEqualToString:[itsUserDefaults objectForKey:@"version"]])  {
    UIAlertView *createUserResponseAlert = [[UIAlertView alloc] initWithTitle:@"New Version!!" message: @"A new version of app is available to download" delegate:selfcancelButtonTitle:nil otherButtonTitles: @”Update", nil];
    [createUserResponseAlert show]; 
    [createUserResponseAlert release];//Avoid if using Automatic reference counting }
Redirect User
-(void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSString *iTunesLink = @"itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id=<appid>&mt=8";
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]]; } 

No comments:

Post a Comment