IOS Detect version Updates

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.