IOS custom version update check

1, effect diagram

IOS custom version update check
prompts for a new version
IOS custom version update check
prompts for a new version (read the update written by AppStore)

2, key points

When you request http://itunes.apple.com/lookup, id=968615456 returns the JSON data about the details of the application, but it’s simpler then

My application returns the JSON data (already formatted):

{"resultCount": 1, "results": [{"advisories": "Unrestricted Web Access", "artistId": 914453386, "artistName": "he Tiancong", "artistViewUrl": "https://itunes.apple.com/us/artist/he-tiancong/ id914453386? Uo=4", "artworkUrl100", "http://is5.mzstatic.com/image/pf/us/r30/Purple5/v4/6f/89/92/6f8992e4-5c10-be87-9242-d933ddb0780a/mzl.jxbacfmg.png", "artworkUrl512": "http://is5.mzstatic.com/image/pf/us/r30/Purple5/v4/6f/89/ 92/6f8992e4-5c10-be87-9242-d933ddb0780a/mzl.jxbacfmg.png", "artworkUrl60": "http://is3.mzstatic.com/image/pf/us/r30/Purple3/v4/2e/cc/a9/2ecca990-b82a-a238-793a-a16b59b56389/AppIcon60x60_U00402x.pn "G", "bundleId", "CampusOfGLUT", "contentAdvisoryRating", "17+", "currency", "USD", "description", "Guilin University of Technology" - campus link formally launched! Application provides: 1, school news, notice and other trends; 2, schools, colleges, learning, etc., 3, study, life and many other columns, sharing and exchange platform ~ welcome to provide suggestions and evaluation! E-mail: ihetiancong@qq.com QQ:3027201361 "," features "," iosUniversal "," fileSizeBytes "," 6436734 "," formattedPrice "," Free "," genreIds "," 6017 "," 6012 "," genres "," Education "," Lifestyle "," ipadScreenshotUrls ": [" http://a1.mzstatic.com/us/r30/Purple3/v4/cf/36/c1/cf36c120-3798-303d-6ae6-cb70da8c7b18/screen480x480.jpeg "," http://a3.mzstatic.com/us/r30/Purple3/v4/4c/34/19/ 4c3419c4-c777-f202-0f5a-a1e733bf37a8/screen480x480.jpeg "," http://a2.mzstatic.com/us/r30/Purple5/v4/9e/9b/35/9e9b3592-4e93-14 "8b-0fd8-73d8ed389388/screen480x480.jpeg", "isGameCenterEnabled": false "kind": "software", "languageCodesISO2A", "EN", "FR", "DE", "JA", "KO", "PL", "RU", "ZH", "ES", "ZH", "" UK "," minimumOsVersion "," 8.1 "," price ": 0," primaryGenreId ": 6017," primaryGenreName "," Education "," releaseDate "," 2015-03-18T09:34:28Z "," releaseNotes "- in those years, last updated version - 1, optimization of iPhone and iPad Under the display 2, increase the topic icon, more eye-catching content 3, increase the number of updates not essential - in those years, we together said topic - 1, thank you very much for those years I was rejected by the girl, they make me full, thank you very much for those 2 growth I take care of their teacher. Let me worry about learning, thank you very much for 3 of those years I trusted students, they let me cherish, thank you very much for those 4 years, miss I is insist on yourself, you make me believe in myself - finally - 1, should be used for the I graduation design works, do not provide business information, thank you 2, support the application of school news for reference only, because of reasons, may not display individual news, please visit the real dynamic (www.glut.edu.cn), 3 campus talk The meaning is to the school information together again through the mobile Internet, this is a trend of the future information, 4 other questions please contact: ihetiancong@qq.com - thank you - "screenshotUrls", "http:// a2.mzstatic.com/us/r30/Purple1/v4/1f/bf/32/1fbf321a-c22b-f938-0d84-17e65730e7a9/screen1136x1136.jpeg": "," http://a5.mzstatic.com/us/r30/Purple3/v4/c9/92/ec/c992ec71-7576-6334-3ebb-4aa857880219/screen1136x1136.jpeg "," http://a1.mzstatic.com/us/ r30/Purple5/v4/72/27/ae/7227aed1-62fa-6946-e63e-52090ce6a021/screen1136x1136.jpeg "," http://a4.mzstatic.com/us/r30/Purple2/v4/13/46/d3/1346d396-4126-ab48-ae15-b0038b92bd68/screen1136x1136 ".jpeg", "sellerName": "he Tiancong", "sellerUrl", "http://weibo.com/iHTCapp", "supportedDevices", "iPhone5c", "iPhone6Plus", "iPodTouchFifthGen", "iPadThirdGen4G", "iPad2Wifi", "iPadFourthGen", "iPhone5s", "iPhone4S", "iPadThirdGen", "iPad23G", "iPhone6", "iPadFourthGen4G", "iPhone5", "iPadMini", "iPadMini4G", "trackCensoredName": "Guilin University of Technology - campus", "trackContentRating", "17+", "trackId": 968615456, "trackName": "Guilin University of Technology - campus", "trackViewUrl": "https://itunes.apple.com/us/app/gui-lin-li-gong-da-xue-xiao/id968615456? Mt=8& uo=4", "version", "1.3", "wrapperType": "software"}]}

3, check the update Demo

  • Check for updates [AFNetworkingUtils getRequestWithUrl:@ “http://itunes.apple.com/lookup? Id=968615456” afterExecute:^ (NSDictionary *resultDic) {float version =[[[[resultDic objectForKey:@ “results” objectAtIndex:0] “valueForKey:@” version “NSDictionary *infoDic=[[NSBundle mainBundle] infoDictionary] floatValue]; [[infoDic valueForKey:@; float currentVersion =” CFBundleShortVersionString “floatValue]; if (version> currentVersion) {NSString *alertTitle=[@” – Guilin University of Technology campus V stringByAppendingString:[NSString stringWithFormat:@ “%0.1f” version]] NSString *alertMsg=@ “; if you want to update? “; //NSString *alertMsg = [[[resultDic objectForKey:@” results “objectAtIndex:0] valueForKey:@” releaseNotes “*alertView=[[UIAlertView alloc] initWithTitle:alertTitle message:alertMsg delegate:self UIAlertView cancelButtonTitle:@” later the new “otherButtonTitles:@”, “nil] [alertView update; show] onError:^{;}}}];
  • Jump to the AppStore update NSString *url = @ “https://itunes.apple.com/us/app/gui-lin-li-gong-da-xue-xiao/id968615456? Mt=8& uo=4; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]”;

4, custom into a tool

  • This method is called when using
#pragma mark - checks the version update - (void) checkUpdate{InformationHandleTool * tool = [InformationHandleTool sharedInfoTool]; [tool checkUpdateWithAppID:@ "968615456" success:^ (NSDictionary *resultDic, BOOL isNewVersion, NSString *newVersion if (isNewVersion)) {}} {[self showUpdateView:newVersion]; failure:^ (NSError *error) {};}];
  • Network request method – (void) checkUpdateWithAppID: (NSString) appID (success: (void ^ (NSDictionary) resultDic, BOOL isNewVersion, NSString newVersion success (void)) failure: (^) (NSError error) failure #pragma mark) – check the version of the update / – (void) checkUpdateWithAppID: (NSString *) appID (void ^ (success: (NSDictionary) *resultDic, BOOL isNewVersion, NSString * newVersion success failure: (void)) (^) (NSError *error) failure *manager=[AFHTTPRequestOperationManager) {AFHTTPRequestOperationManager manager]; manager.requestSerializer=[AFHTTPRequestSerializer serializer]; manager.responseSerializer=[AFHTTPResponseSerializer serializer]; NSString *encodingUrl=[[@ http:// itunes.apple.com/lookup id= stringByAppendingString:appID] stringByAddingPerce? ” NtEscapesUsingEncoding:NSUTF8StringEncoding]; [manager GET:encodingUrl parameters:nil success:^ (AFHTTPRequestOperation *operation, ID responseObject NSDictionary *resultDic=[NSJSONSerialization JSONObjectWithData:responseObject options: NSJSONReadingMutableLeaves) {error:nil]; NSString * versionStr =[[[resultDic objectForKey:@ “results” objectAtIndex:0] valueForKey:@ “version”]; float version =[versionStr floatValue]; //self.iTunesLink=[[[resultDic objectForKey:@ “results” objectAtIndex:0] valueForKey:@ “trackViewUrl”]; NSDictionary *infoDic=[[NSBundle mainBundle] infoDictionary]; float currentVersion = [[infoDic valueForKey:@ “CFBundleShortVersionString” floatValue] (version> currentVers; if Ion (resultDic) {success, YES, versionStr);}else{success (resultDic, NO, versionStr);}} failure:^ (AFHTTPRequestOperation *operation, NSError *error) {failure (error);}];}
  • Reminding method – (void) showUpdateView: (NSString) newVersion
    * Note: This is iOS8 UIAlertController / (void) showUpdateView: (NSString * newVersion) {NSString *alertMsg=[[@ “- Guilin University of Technology campus V” stringByAppendingString:[NSString stringWithFormat:@ “%0.1f” [newVersion floatValue]]] stringByAppendingString:@ “, to experience the latest version! “*alert = [UIAlertController]; UIAlertController alertControllerWithTitle:@ found a new version of” message:alertMsg preferredStyle:UIAlertControllerStyleAlert] [alert addAction:[UIAlertAction actionWithTitle:@; / / Add button “Cancel” style: UIAlertActionStyleCancel handler:^ (UIAlertAction *action) {}]]; [alert addAction:[UIAlertAction “style:UIAlertActionStyleDefault handler:^ actionWithTitle:@” update (UIAlertAction *action) {NSString *str = @ “https://itunes.apple.com/us/app /gui-lin-li-gong-da-xue-xiao/id968615456? Mt=8&amp uo=4 [[UIApplication; sharedApplication] openURL:[NSURL;” URLWithString:str]]; [self presentViewController:alert}]]; animated:YES completion:nil];}

5, check enhancement

  • The server version and the local version are optional, such as server 1.4.1 and local 1.4, which can also be checked.
NSString * serverVersion =[[[resultDic objectForKey:@ "results" objectAtIndex:0] valueForKey:@ "version"]; NSString localVersion = [SystemUtils * getVersionSting]; / / to "separate." and then assigned to different digital array NSArray * serverArray = [serverVersion componentsSeparatedByString:@] "."; NSArray = [localVersion * localArray componentsSeparatedByString:@ "."]; for (int i = 0 i; < serverArray.count; i++) {/ / the server version for reference, to determine the local version number is less than the server version, return directly (and judge for the new version, such as server 1.5.1 local 1.5 (I) if > (localArray.count -1)) {/ / a new version, prompt! Break;} / / the latest version of the server version of the corresponding local if ([serverArray[i] intValue] more than > [localArray[i] intValue]) {/ / a new version, prompt! Break;}