欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2017年05月06日 09:26:38   作者:飛翔云端的魚  
本篇文章主要介紹了ios實(shí)現(xiàn)app強(qiáng)制更新功能,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

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

效果圖:

在appdelegate里面寫下面代碼

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

-(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自身版本號
  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:@"版本過低,需要升級到最新版本"];
  UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"升級提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
  UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"現(xiàn)在升級" 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從后臺切到前臺時調(diào)用的方法
- (void)applicationDidBecomeActive:(UIApplication * )application
{
  [self VersonUpdate];
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • cmake ios終端下執(zhí)行提示錯誤 iOS version not found, tested: [5.0;5.1;6.0;6.1;7.0;8.3]的解決方案

    cmake ios終端下執(zhí)行提示錯誤 iOS version not found, tested: [5.0;5.1;6

    這篇文章主要介紹了cmake ios終端下執(zhí)行提示錯誤 iOS version not found, tested: [5.0;5.1;6.0;6.1;7.0;8.3]的解決方案的相關(guān)資料,需要的朋友可以參考下
    2016-10-10
  • iOS內(nèi)存管理引用計數(shù)示例分析

    iOS內(nèi)存管理引用計數(shù)示例分析

    這篇文章主要為大家介紹了iOS內(nèi)存管理引用計數(shù)示例分析詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-01-01
  • iOS利用UIScrollView實(shí)現(xiàn)無限滾動效果

    iOS利用UIScrollView實(shí)現(xiàn)無限滾動效果

    這篇文章主要給大家介紹了iOS如何利用UIScrollView實(shí)現(xiàn)無限滾動的效果,首先需要說明的是,文本所講的是一種"笨辦法",但是好理解且容易實(shí)現(xiàn),在圖片不多的時候用它也無妨。感興趣的朋友們下面跟著小編一起來學(xué)習(xí)學(xué)習(xí)吧。
    2016-12-12
  • ios開發(fā)Flutter之?dāng)?shù)據(jù)存儲

    ios開發(fā)Flutter之?dāng)?shù)據(jù)存儲

    這篇文章主要為大家介紹了ios開發(fā)Flutter之?dāng)?shù)據(jù)存儲的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-07-07
  • 解決ios模擬器不能彈出鍵盤問題的方法

    解決ios模擬器不能彈出鍵盤問題的方法

    這篇文章主要為大家詳細(xì)介紹了解決ios模擬器不能彈出鍵盤問題的方法,大多數(shù)原因是誤用了快捷鍵,如何解決?感興趣的小伙伴們可以參考一下
    2016-03-03
  • Objective C從遠(yuǎn)程url下載圖片方法匯總

    Objective C從遠(yuǎn)程url下載圖片方法匯總

    本文給大家分享了2則使用Objective C從遠(yuǎn)程url下載圖片的方法,都是個人項目中使用的,匯總下推薦給大家,有需要的小伙伴可以參考下。
    2015-05-05
  • Objective-C的NSOperation多線程類基本使用指南

    Objective-C的NSOperation多線程類基本使用指南

    這篇文章主要介紹了Objective-C的NSOperation多線程類基本使用指南,談到了Operations的執(zhí)行順序和并發(fā)量等設(shè)置操作,需要的朋友可以參考下
    2016-02-02
  • iOS實(shí)現(xiàn)側(cè)滑欄效果

    iOS實(shí)現(xiàn)側(cè)滑欄效果

    這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)側(cè)滑欄效果,點(diǎn)擊側(cè)邊拉出相應(yīng)菜單,感興趣的小伙伴們可以參考一下
    2016-08-08
  • iOS中NSPredicate謂詞的使用

    iOS中NSPredicate謂詞的使用

    這篇文章主要給大家介紹了關(guān)于iOS中NSPredicate謂詞的使用方法,文中通過示例代碼介紹的非常詳細(xì),對各位iOS開發(fā)者們具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-01-01
  • iOS中的UISlider滑塊組件用法總結(jié)

    iOS中的UISlider滑塊組件用法總結(jié)

    不僅是滑動開關(guān),UISlider組件也是常用的進(jìn)度條制作工具,這里我們就一起來看一下iOS中的UISlider滑塊組件用法總結(jié),需要的朋友可以參考下
    2016-06-06

最新評論