iOS實現應用更新及強制更新


調用更新接口返回字段:
result =     {
            descr = "";
            isupdate = 1;//是否更新
            qzupdate = 0;//是否強制更新
            updateurl = " http://www.baidu.com";//更新地址
            versioncode = "2.0";//版本號
        };
 
根據獲取的是否更新、強制更新以及新版本的序號進行判斷
(1)強制更新:無論如何彈出提示框且只有一個選項,點擊跳轉更新
(2)普通更新:彈出提示框有“取消”和“確定”兩個選項:點擊確定跳轉更新;點擊取消本地保存待更新版本號,再次進入時則和本地保存的待更新版本號進行判斷,如果相同則彈出提示框,不相同則不操作(例如V1.1版本普通更新選擇”取消”后,后面V1.1的版本不會再次提示,但V1.2版本更新仍會提示)
(3)無更新:不操作
 
 
本地保存數據:
待更新的版本序號:@“Version_To_Update"

AppDelegate:
//檢查版本更新
-(void)checkVersionUpdate{
   
    //檢查更新
    NSString *stringVer = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey];
    [[NetWorkRequest shareRequest]updateNewVersionWithversioncode:stringVer serverSuccessFn:^(id response) {
        if ([[response objectForKey:@"qzupdate"] intValue] == 1 &&
            [[response objectForKey:@"updateurl"] length] > 0) {
            DebugLog(@"需要強制更新");
            NSString *mes = [NSString stringWithFormat:@"發現最新版本%@,需更新后才能繼續使用\n更新內容:%@",[response objectForKey:@"versioncode"],[response objectForKey:@"descr"]];
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示"
                                                                message:mes
                                                               delegate:self
                                                      cancelButtonTitle:nil
                                                      otherButtonTitles:@"確定", nil];
            alertView.tag = 1001;
            [alertView show];
        }else if ([[response objectForKey:@"isupdate"] intValue] == 1 &&
                  [[response objectForKey:@"updateurl"] length] > 0) {
           
            NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
            NSString *version = [userDefaults objectForKey:@"Version_To_Update"];//待更新的版本
            version_to_update = [response objectForKey:@"versioncode"];
            if ([stringVer floatValue] < [version floatValue] &&
                [version_to_update floatValue] <= [version floatValue]) {
                //當前待更新版本已點擊取消並在本地保存的待更新版本,不彈出提示框
               
            }else {
                //彈出提示框進行更新
               
               
                NSString *mes = [NSString stringWithFormat:@"發現最新版本%@,是否更新?\n更新內容:%@",[response objectForKey:@"versioncode"],[response objectForKey:@"descr"]];
                UIAlertView *alertTi = [[UIAlertView alloc] initWithTitle:@"提示"
                                                                  message:mes
                                                                 delegate:self
                                                        cancelButtonTitle:@"取消"
                                                        otherButtonTitles:@"確定", nil];
                alertTi.tag = 1002;
                [alertTi show];
            }
           
        }else{
            //DebugLog(@"不需要更新");
        }
    } serverFailureFn:^(NSError *error, id response) {
       
    }];
}

 

 

 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM