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 updateNserror *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]; //get the latest version number applied on the servernsarray* arr=[infodict[@"version"] Componentsseparatedbystring:@"."]; Nsinteger updateversion=0; for(intI=0; i<arr.count; i++) { if(i==0) {updateversion+=[arr[i] integervalue]* +; } Else if(i==1) {updateversion+=[arr[i] integervalue]* -; } Else if(i==2) {updateversion+=[arr[i] integervalue]*Ten; } 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 deviceNsdictionary *infodic =[[NSBundle Mainbundle] infodictionary]; Nsarray* Arr2=[[infodic Objectforkey:@"cfbundleshortversionstring"] Componentsseparatedbystring:@"."]; Nsinteger CurrentVersion=0; for(intI=0; i<arr2.count; i++) { if(i==0) {CurrentVersion+=[arr2[i] integervalue]* +; } Else if(i==1) {CurrentVersion+=[arr2[i] integervalue]* -; } Else if(i==2) {CurrentVersion+=[arr2[i] integervalue]*Ten; } 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:@"new version%@ found, updated", infodict[@"version"]]; Uialertview*alert = [[Uialertview alloc] Initwithtitle:titlestr message:messagestrDelegate: 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 from the App StoreSkstoreproductviewcontroller *STOREPRODUCTVC =[[Skstoreproductviewcontroller alloc] init]; STOREPRODUCTVC.Delegate=Self ; Nsdictionary*dict = [Nsdictionary dictionarywithobject:@"shelves AppID"Forkey:skstoreproductparameteritunesitemidentifier]; [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.
iOS automatically detects version updates