This is what I do in the project about version updates, first of all, to talk about the general idea.
Idea: Get the current version number from the server at program startup and compare it to the local version number.
1. If a mandatory update is required, only the update option is available.
2. If the regular update provides "yes", "no", if the user clicks No, then the local record gets the version number, if there is no new version iteration, not in the prompt update
The code is as follows:
+ (void) Checkversionwithblock: (void (^) (NSString *)) Theblock
{Nsuserdefaults*userdefaults =[Nsuserdefaults Standarduserdefaults]; Nsurlrequest*request =[Nsurlrequest Requestwithurl:[nsurl urlwithstring:checkversionurlstring]; [Self postdatawithpath:request withuseactivityindicator:no withresponseblock:^(IDresult, Nserror *err) { //1. Get the current version numberNsdictionary *infodictionary =[[NSBundle Mainbundle] infodictionary]; NSString*appversion = [Infodictionary objectforkey:@"cfbundleshortversionstring"]; if(Result) {NSString*newversion = result[@"version"];BOOL isneedforceupdate=NO; BOOL isneedupdate=NO;
Determine the need to force updates, normal updates
//Your judgment codeif(isneedforceupdate) {//Force Update[[Wkalertview shareinstance] Showtitle:@"Update Tips"Withmessage:messagestr withc Ancelbutton:nil Withotherbutton:@"Update"Withmessagealignmentleft:yes Withhanderb Lock:^ (Uialertview *Alertview, Nsinteger buttonindex) { if(Buttonindex = =0) {//is a[[uiapplication sharedapplication] Openurl:[nsurl urlwithstring:u Pdateversionurlstring]]; } }]; [[Nsuserdefaults Standarduserdefaults] setobject:@ (isneedforceupdate) Forkey:@"isneedforceupdate"]; }Else if(isneedupdate) {//Prompt for Updates//version number of the last detected update//version number of this detection update//Have you canceledNSString *lastchekedversion =[Userdefaults Stringforkey:lastcheckedversionkey]; BOOL Isneedshowalert; if(! [NewVersion Isequaltostring:lastchekedversion]) {//need to displayIsneedshowalert =YES; }Else{Isneedshowalert=NO; } if(Isneedshowalert) {[[Wkalertview shareinstance] Showtitle:@"Update Tips"Withmessage:messagestr Withcancelbutton:@"No"Withotherbutton:@"is a"Withmessagealignmentleft:yes Wit Hhanderblock:^ (Uialertview *Alertview, Nsinteger buttonindex) { if(Buttonindex = =1) {//is a[[Uiap Plication Sharedapplication] Openurl:[nsurl urlwithstring:updateversionurlstring]]; } if(Buttonindex = =0) {//No//Store last detected updated version string[Userdefaults setvalue:newversion Forkey:lastcheckedversionkey ]; } }]; [[Nsuserdefaults Standarduserdefaults] setobject:@ (isneedupdate) Forkey:@"isneedupdate"]; [[Nsuserdefaults standarduserdefaults]synchronize]; } } } }];}
IOS Detect version Updates