iOS開發之檢查更新,ios開發更新

來源:互聯網
上載者:User

iOS開發之檢查更新,ios開發更新
iOS開發之檢查更新

#pragma mark - 檢查更新

- ( void )checkUpdateWithAPPID:( NSString  *)APPID {      //擷取當前應用版本號碼      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:@ "正在檢查更新..." ];      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:@ "最新版本為%@,是否更新?" ,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:@ "提示"  message:msg delegate: self  cancelButtonTitle:@ "暫不"  otherButtonTitles:@ "立即更新" nil ];                          alertView.tag = 1000;                          [alertView show];                          [alertView release];                      } else                      {                          UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@ "提示"  message:@ "您使用的是最新版本!"  delegate: self  cancelButtonTitle: nil  otherButtonTitles:@ "確定" 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:@ "操作失敗,請稍候再試!" ];          [ 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]];              }          }      } }

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.