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) {
       
    }];
}
相關文章
相關標籤/搜索