iOS软件更新问题

1 软件中需要自己在后台服务器中,设定新的版本号。每次登陆软件从后台拉取数据,用最新版本号与当前版本号进行比较。实现软件更新。 2 每次登陆软件从苹果服务器拉

1.软件中需要自己在后台服务器中,设定新的版本号。每次登陆软件从后台拉取数据,用最新版本号与当前版本号进行比较。实现软件更新。

2.每次登陆软件从苹果服务器拉取数据,用最新版本号与当前版本号进行比较。实现软件更新。

第一种检测更新方法的优点是:检测更新速度快、检测稳定;缺点是:和app store上的应用版本号不同步(app上架需要审核时间,不确定什么时候成功更新到app store上)。第二种方法检测更新方法的优点是:检测版本号是实时同步的;缺点是:苹果网络不稳定,检测更新延时严重,部分APP获取不到任何参数。

个人喜欢使用第一种,只需要后台服务器根据app store上架版本号手动修改数据就行了,APP版本号格式也可以自己定义。

 

代码如下:

#pragma mark--获取最新版本

- (void)getNewVerion

{   // 1.取得接口字符串

    NSString *getInformation = K_AppInfo;

    // 2.获取数据

    [UpDataDataService requestData:getInformation withResult:^(id result) {

        NSDictionary *information = [result objectForKey:@"results"][0];

        // 1)获取最新版本

        NSString *newVersion = [information objectForKey:@"version"];

        // 2)获取当前版本

        NSString *nowVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];

        NSString *message = [[NSString alloc] initWithFormat:@"****最新版本:%@,为了不影响您的使用,请尽快更新!",newVersion];

        // 3)判断最新版本是否大于当前版本

        if ([newVersion integerValue]>[nowVersion integerValue])

        {   // 4)在异步调用中对UI设置必须回调到主线程

            dispatch_async(dispatch_get_main_queue(), ^{

                UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:@"提示更新" message:message delegate:self cancelButtonTitle:@"取消更新" otherButtonTitles:@"确定更新", nil];

                [alerView show];

            });

        }

    }];

}