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) {
       
    }];
}
 
 
 

猜你喜欢

转载自www.cnblogs.com/ios-wmm/p/10216070.html