iOS Development app Update

Source: Internet
Author: User

#import "ViewController.h"//1 must first configure their own project in the store AppID, configure the best to run on the real machine to see the full effect Oh#defineStoreappid @ "1080182980"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //a code implementation detection update[self Hsupdateapp];}/** * Celestial Special Detection app update*/-(void) hsupdateapp{//2 Get the current project version number firstNsdictionary *infodic=[[NSBundle Mainbundle] infodictionary]; NSString*currentversion=infodic[@"cfbundleshortversionstring"]; //3 Getting the AppStore version number from the networkNserror *error; NSData*response = [Nsurlconnection sendsynchronousrequest:[nsurlrequest requestwithurl:[nsurl URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@", Storeappid]]    Returningresponse:nil Error:nil]; if(Response = =Nil) {NSLog (@"you're not connected to the network."); return; } nsdictionary*appinfodic = [Nsjsonserialization jsonobjectwithdata:response options:nsjsonreadingmutableleaves error:&ERROR]; if(Error) {NSLog (@"hsupdateapperror:%@", error); return; } Nsarray*array = appinfodic[@"Results"]; Nsdictionary*dic = array[0]; NSString*appstoreversion = dic[@"version"]; //Print Version numberNSLog (@"Current version number:%@\n Store version number:%@", currentversion,appstoreversion); //4 The current version number is less than the store version number, update    if([CurrentVersion Floatvalue] <[appstoreversion Floatvalue]) {Uialertview*alert = [[Uialertview alloc] Initwithtitle:@"version is updated"Message:[nsstring stringWithFormat:@"new version (%@) detected, updated?", Appstoreversion]Delegate: Self Cancelbuttontitle:@"Cancel"Otherbuttontitles:@"Update", nil];    [Alert show]; }Else{NSLog (@"The version number seems to be bigger than the store. No updates detected"); }}- (void) Alertview: (uialertview*) Alertview Clickedbuttonatindex: (nsinteger) buttonindex{//5 Implementation jumps to the store for updates    if(buttonindex==1)    {        //6 Here to add the application in the App Store address, convenient for users to update, a way to achieve the following:Nsurl *url = [Nsurl urlwithstring:[nsstring stringWithFormat:@"https://itunes.apple.com/us/app/id%@?ls=1&mt=8", Storeappid]];    [[UIApplication sharedapplication] openurl:url]; }}@end

iOS Development app Update

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.