IOS development check and update

Source: Internet
Author: User

IOS development check and update
IOS development check and update

# Pragma mark-check for updates

- ( void )checkUpdateWithAPPID:( NSString  *)APPID {      // Obtain the current application version      NSDictionary  *appInfo = [[ NSBundle  mainBundle] infoDictionary];          NSString  *currentVersion = [appInfo objectForKey:@ "CFBundleVersion" ];            NSString  *updateUrlString = [ NSString  stringWithFormat:@ "http://itunes.apple.com/lookup?id=%@" ,APPID];      NSURL  *updateUrl = [ NSURL  URLWithString:updateUrlString];      versionRequest = [ASIFormDataRequest requestWithURL:updateUrl];      [versionRequest setRequestMethod:@ "GET" ];      [versionRequest setTimeOutSeconds:60];      [versionRequest addRequestHeader:@ "Content-Type"  value:@ "application/json" ];            //loading view      CustomAlertView *checkingAlertView = [[CustomAlertView alloc] initWithFrame:NAVIGATION_FRAME style:CustomAlertViewStyleDefault noticeText:@ "Checking for updates ..." ];      checkingAlertView.userInteractionEnabled =  YES ;      [ self .navigationController.view addSubview:checkingAlertView];      [checkingAlertView release];            [versionRequest setCompletionBlock:^{                    [checkingAlertView removeFromSuperview];                    NSError  *error =  nil ;          NSDictionary  *dict = [ NSJSONSerialization  JSONObjectWithData:[versionRequest responseData] options: NSJSONReadingMutableContainers  error:&error];          if  (!error) {              if  (dict !=  nil ) {                  //            DLog(@"dict %@",dict);                  int  resultCount = [[dict objectForKey:@ "resultCount" ] integerValue];                  if  (resultCount == 1) {                      NSArray  *resultArray = [dict objectForKey:@ "results" ];                      //                DLog(@"version %@",[resultArray objectAtIndex:0]);                      NSDictionary  *resultDict = [resultArray objectAtIndex:0];                      //                DLog(@"version is %@",[resultDict objectForKey:@"version"]);                      NSString  *newVersion = [resultDict objectForKey:@ "version" ];                                            if  ([newVersion doubleValue] > [currentVersion doubleValue]) {                          NSString  *msg = [ NSString  stringWithFormat:@ "The latest version is % @. Are you sure you want to update it? " ,newVersion];                          newVersionURlString = [[resultDict objectForKey:@ "trackViewUrl" copy ];                          DLog(@ "newVersionUrl is %@" ,newVersionURlString);                          //                    if ([newVersionURlString hasPrefix:@"https"]) {                          //                         [newVersionURlString replaceCharactersInRange:NSMakeRange(0, 5) withString:@"itms-apps"];                          //                    }                          UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@ "Prompt"  message:msg delegate: self  cancelButtonTitle:@ "Not now"  otherButtonTitles:@ "Update now" nil ];                          alertView.tag = 1000;                          [alertView show];                          [alertView release];                      } else                      {                          UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@ "Prompt"  message:@ "You are using the latest version! "  delegate: self  cancelButtonTitle: nil  otherButtonTitles:@ "OK" nil ];                          alertView.tag = 1001;                          [alertView show];                          [alertView release];                      }                  }              }          } else          {              DLog( "error is %@" ,[error debugDescription]);          }      }];            [versionRequest setFailedBlock:^{          [checkingAlertView removeFromSuperview];                    CustomAlertView *alertView = [[CustomAlertView alloc] initWithFrame:NAVIGATION_FRAME style:CustomAlertViewStyleWarning noticeText:@ "Operation failed. Please try again later! " ];          [ self .navigationController.view addSubview:alertView];          [alertView release];          [alertView selfRemoveFromSuperviewAfterSeconds:1.0];      }];            [versionRequest startSynchronous];   }  - ( void )alertView:(UIAlertView *)alertView clickedButtonAtIndex:( NSInteger )buttonIndex {      DLog(@ "newVersionUrl  is %@" ,newVersionURlString);      if  (buttonIndex) {          if  (alertView.tag == 1000) {              if (newVersionURlString)              {                  [[UIApplication sharedApplication] openURL:[ NSURL  URLWithString:newVersionURlString]];              }          }      } }

 

Related Article

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.