Although Apple officially does not allow the app to automatically detect updates, prompting users to download, because Apple will prompt you how many software needs to be updated, but sometimes it is necessary to prompt the user for a new version.
First say the principle:
Every Apple app on the shelves, there will be an application ID, according to this ID we can get to the current program's latest version number, and then compare with their version number, if the same is the latest edition, but not the new version, you can prompt users to manually download the latest version of the program. Because there is an ID so you can locate the app, click to download.
Source:
It is generally recommended to check the updated code in the home controller.
First, you will also import a header file to open the AppStore download update
Appstore#import <StoreKit/StoreKit.h>
Then there's the agent.
Skstoreproductviewcontrollerdelegate
And then start detecting updates
//detection version, version update NSError *error; nsstring *urlstr = @ "http://itunes.apple.com/lookup?id= shelves AppID"; nsurl *url = [nsurl urlwithstring:urlstr]; nsurlrequest *request = [NSURLRequest requestWithURL:url]; NSData *response = [nsurlconnection sendsynchronousrequest:request returningresponse:nil error:nil]; nsdictionary *appinfodict = [nsjsonserialization jsonobjectwithdata:response options:NSJSONReadingMutableLeaves error:&error]; if (Error) { return; } nsarray *resultarray = [appinfodict objectforkey:@ "Results"]; if (![ ReSultarray count]) { return; } nsdictionary *infodict = [ resultarray objectatindex:0]; //gets the latest version number applied on the server nsarray* arr=[infodict[@ "Version"] componentsseparatedbystring:@ "."; NSInteger updateVersion=0; for (int i=0; i<arr.count; i++) { if (i==0) { updateversion+=[arr[i] integervalue]*1000; } else if (i==1) &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBsp; { updateversion+=[arr[i] integerValue]*100; } else if (i==2) { updateVersion+=[arr[i] integerValue]*10; } else if (i==3) { updateversion+=[arr[i] integervalue]*1; } } nsstring *trackname = infodict[@ "TrackName"]; _trackviewurl = infodict[@ "Trackviewurl"];//gets the version number of the app in the current device nsdictionary *infodic = [[nsbundle mainbundle] infodictionary]; nsarray* arr2=[[ infodic objectforkey:@ "cfbundleshortversionstring"] componentsseparatedbystring:@ "."; nsinteger currentversion=0; for (int i=0; i<arr2.count; i++) { if (i==0) { currentVersion+=[arr2[i] integerValue]*1000; } else if (i==1) { currentVersion+=[arr2[i] integerValue]*100; } else if (i==2) { currentVersion+=[arr2[i] integerValue]*10; } else if (i==3) { currentversion+=[arr2[i] integervalue]*1; } } //determine if two versions are the same if ( Currentversion < updateversion) { nsstring *titlestr = [nsstring stringwithformat:@ "Check for updates:%@", trackName]; NSString *messageStr = [NSString stringwithformat:@ "Found new version%@, updated", infodict[@ "Version"]]; uialertview *alert = [[ uialertview alloc] initwithtitle:titlestr message:messagestr delegate:self cancelbuttontitle:@ "Cancel" otherbuttontitles:@ "Upgrade", nil]; To distinguish between other pop-up boxes alert.tag = 1112427256; [alert show]; }
And then the user is less of a problem.
- (void) Alertview: (uialertview *) Alertview clickedbuttonatindex: (Nsinteger) buttonIndex { if (alertview.tag == 1112427256) { if (buttonindex == 1) { / /Click the "Upgrade" button to open the app's details page on App store skstoreproductviewcontroller *storeproductvc = [[skstoreproductviewcontroller alloc] init]; storeproductvc.delegate = self; nsdictionary *dict = [nsdictionary dictionarywithobject:@ "Shelves AppID" forkey: skstoreproductparameteritunesitemidentifier]; &Nbsp; [storeproductvc loadproductwithparameters:dict completionblock:^ (Bool result, nserror *error) { if (Result) { [self presentviewcontroller:storeproductvc animated:YES completion:nil]; } }]; } }}
There is a situation where the user opens AppStore but returns without downloading
-(void) Productviewcontrollerdidfinish: (Skstoreproductviewcontroller *) viewcontroller{[Viewcontroller Dismissviewcontrolleranimated:yes Completion:nil];}
OK, it's over here. In this way you can detect whether the app is the latest version, and users can see in real time, the most important thing is that Apple audit can pass.
This article is from the "Red Corner Antelope" blog, please be sure to keep this source http://2254359459.blog.51cto.com/10776102/1876839
iOS automatically detects version updates