真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

ios實(shí)現(xiàn)app強(qiáng)制更新功能-創(chuàng)新互聯(lián)

最近因項(xiàng)目需求,需要用到強(qiáng)制更新功能,網(wǎng)上搜了一下,挺多的,但是把網(wǎng)上的代碼拷貝以后,發(fā)現(xiàn)一個(gè)bug,就是進(jìn)app,彈出框顯示,點(diǎn)擊現(xiàn)在升級(jí),跳轉(zhuǎn)到AppStore下載里面,但是我不下載,又切回到app里面,發(fā)現(xiàn)彈出框就不跳了,其實(shí)也簡(jiǎn)單,就是appdelegate里面有個(gè)代理方法,就是當(dāng)app從后臺(tái)切到前臺(tái)走的方法,將強(qiáng)制更新方法在這里面在調(diào)用一下就行了~~~話不多說(shuō),上代碼!?。∮玫脑捴苯诱迟N復(fù)制~

創(chuàng)新互聯(lián)于2013年成立,是專(zhuān)業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、成都外貿(mào)網(wǎng)站建設(shè)公司網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元禮縣做網(wǎng)站,已為上家服務(wù),為禮縣各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:028-86922220

效果圖:

ios實(shí)現(xiàn)app強(qiáng)制更新功能

在appdelegate里面寫(xiě)下面代碼

//提示版本更新
 [self VersonUpdate];
#pragma mark ------提示用戶(hù)版本更新------

-(void)VersonUpdate{

  //定義app地址
  NSString *urld = [NSString  stringWithFormat:@"http://itunes.apple.com/lookup?id=%d",1178114725];

  NSURL *url = [NSURL URLWithString:urld];

  NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];

  [request setHTTPMethod:@"POST"];

  NSURLSession *session = [NSURLSession sharedSession];

  NSURLSessionDataTask *task = [session dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

    NSLog(@"%@",response);

    NSMutableDictionary *receiveStatusDic = [[NSMutableDictionary alloc]init];

    if (data) {

      NSDictionary *receiveDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
      if ([[receiveDic valueForKey:@"resultCount"] intValue] > 0) {

        [receiveStatusDic setObject:@"1" forKey:@"status"];

        [receiveStatusDic setObject:[[[receiveDic valueForKey:@"results"] objectAtIndex:0] valueForKey:@"version"]  forKey:@"version"];

        [self performSelectorOnMainThread:@selector(receiveData:) withObject:receiveStatusDic waitUntilDone:NO];


      }else{

        [receiveStatusDic setValue:@"1" forKey:@"status"];


      }
    }else{


      [receiveStatusDic setValue:@"-1" forKey:@"status"];
    }


  }];

  [task resume];

}
-(void)receiveData:(id)sender
{
  //獲取APP自身版本號(hào)
  NSString *localVersion = [[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleShortVersionString"];

  NSArray *localArray = [localVersion componentsSeparatedByString:@"."];//1.0
  NSArray *versionArray = [sender[@"version"] componentsSeparatedByString:@"."];//3 2.1.1


//  if ((versionArray.count == 2) && (localArray.count == versionArray.count)) {

    if ([localArray[0] intValue] < [versionArray[0] intValue]) {

      [self updateVersion];

    }else if ([localArray[0] intValue] == [versionArray[0] intValue]){
      if ([localArray[1] intValue] < [versionArray[1] intValue]) {
        [self updateVersion];

      }else if ([localArray[1] intValue] == [versionArray[1] intValue]){
        if ([localArray[2] intValue] < [versionArray[2] intValue]) {

          [self updateVersion];

        }
      }
    }
//  }

}

-(void)updateVersion{

  NSString *msg = [NSString stringWithFormat:@"版本過(guò)低,需要升級(jí)到最新版本"];
  UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"升級(jí)提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
  UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"現(xiàn)在升級(jí)" style:UIAlertActionStyleDestructive handler:^(UIAlertAction*action) {

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/cn/app/m-help/id1178114725?mt=8"]];
    [[UIApplication sharedApplication]openURL:url];
  }];
  [alertController addAction:otherAction];
  [self.window.rootViewController presentViewController:alertController animated:YES completion:nil];

}
//當(dāng)app從后臺(tái)切到前臺(tái)時(shí)調(diào)用的方法
- (void)applicationDidBecomeActive:(UIApplication * )application
{
  [self VersonUpdate];
}

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站www.cdcxhl.com,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。


當(dāng)前題目:ios實(shí)現(xiàn)app強(qiáng)制更新功能-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)鏈接:http://weahome.cn/article/hdhge.html

其他資訊

在線咨詢(xún)

微信咨詢(xún)

電話咨詢(xún)

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部