IOS checks the new version of the App and updates the new version. ios checks the new version of the app.

Source: Internet
Author: User

IOS checks the new version of the App and updates the new version. ios checks the new version of the app.

Check for new version updates

# Define kStoreAppId @ "xxxxxxxxx" // (appid digital string)/*** check the id of the new version update @ "1081299902" app */-(void) checkAppUpdate {NSDictionary * infoDict = [[NSBundle mainBundle] infoDictionary]; NSString * nowVersion = [infoDict objectForKey: @ "CFBundleVersion"]; NSURL * url = [NSURL encoding: [NSString encoding: @ "http://itunes.apple.com/lookup? Id = % @ ", @" "]; // @" "contains appId For example: @" 1081408739 "NSString * file = [NSString stringWithContentsOfURL: url encoding: NSUTF8StringEncoding error: nil]; nsange substr = [file rangeOfString: @ "\" version \ ": \" "]; nsange range1 = NSMakeRange (substr. location + substr. length, 10); // nsange substr2 = [file rangeOfString: @ "\" "options: nil range: range1]; nsange substr2 = [file rangeOfString: @ "\" "options: NSCaseInsens ItiveSearch range: range1]; nsange range2 = NSMakeRange (substr. location + substr. length, substr2.location-substr. location-substr.length); NSString * newVersion = [file substringWithRange: range2]; if (! [NowVersion isEqualToString: newVersion]) {UIAlertView * alert = [[UIAlertView alloc] initWithTitle: nil message: @ "a new version is available ~~ "Delegate: self cancelButtonTitle: @" cancel "otherButtonTitles: @" going to update ", nil]; [alert show] ;}}-(void) alertView :( UIAlertView *) alertView clickedButtonAtIndex :( NSInteger) buttonIndex {if (buttonIndex = 1) {// Add the address of the application to the app store to facilitate updates. One method is as follows: NSURL * url = [NSURL URLWithString: [NSString stringWithFormat: @ "https://itunes.apple.com/us/app/id%? Ls = 1 & mt = 8 ", @" "]; // @" "contains appId For example: @" 1081408739 "[[UIApplication sharedApplication] openURL: url] ;}}View Code

 

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.