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, 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": " id914453386? Uo=4", "artworkUrl100", "", "artworkUrl512": " 92/6f8992e4-5c10-be87-9242-d933ddb0780a/mzl.jxbacfmg.png", "artworkUrl60": " "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: QQ:3027201361 "," features "," iosUniversal "," fileSizeBytes "," 6436734 "," formattedPrice "," Free "," genreIds "," 6017 "," 6012 "," genres "," Education "," Lifestyle "," ipadScreenshotUrls ": [" "," 4c3419c4-c777-f202-0f5a-a1e733bf37a8/screen480x480.jpeg "," "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 (, 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: - thank you - "screenshotUrls", "http://": "," "," r30/Purple5/v4/72/27/ae/7227aed1-62fa-6946-e63e-52090ce6a021/screen1136x1136.jpeg "," ".jpeg", "sellerName": "he Tiancong", "sellerUrl", "", "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": " Mt=8& uo=4", "version", "1.3", "wrapperType": "software"}]}

3, check the update Demo

  • Check for updates [AFNetworkingUtils getRequestWithUrl:@ “ 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 = @ “ 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:// 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 = @ “ /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;}