提示app 版本更新

2018-10-19  本文已影响3人  心情的蛊惑

开发中我们可能会遇到这样的需求,当AppStore中有新版本迭代更新,在用户点开APP的时候弹框提醒客户去AppStore更新APP。这里面就有个关键点,判断当前APP与AppStore中的版本高低,若一样,则无需进行提示;反之则弹框提示。

首先,说一下version和bulid的区别:
iOS的版本号,一个叫做Version,一个叫做Build,这两个值都可以在Xcode中选中target,点击"General"后看到。
Version在plist文件中的key是“CFBundleShortVersionString”,和AppStore上的版本号保持一致。
Build在plist中的key是“CFBundleVersion”,代表build的版本号,该值每次build之后都应该增加1。

//获得应用的Verison号:
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];

//获得build号:
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];

那我们怎么做到提示更新?
我们的项目中是对比版本号,然后弹框

[SYActionManager Post:@"https://itunes.apple.com/lookup?id=你的应用ID" parameters:nil ActionWithSuccess:^(SYActionBase *action, id responseObject, NSURLSessionDataTask *operation) {
        NSArray *array = responseObject[@"results"];
        NSDictionary *dict = [array lastObject];
        NSLog(@"当前版本为:%@", dict[@"version"]);
       
        //获取手机的版本号
        NSString *currentVersionPhone =  [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
       
        if (![currentVersionPhone isEqualToString:dict[@"version"]]) {
            [SYCustomAlterView showSyAlterViewContent:@"发现需要升级的版本,现在去更新" clickFinsh:^{
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"应用链接"]];
            }];
            
        }
    } Failure:^(SYActionBase *action, NSError *error, NSURLSessionDataTask *operation) {

        [SYUntil showErrorHUDViewAtView:K_SY_KeyWindow WithTitle:@"请求失败!"];
    }];
    
上一篇 下一篇

猜你喜欢

热点阅读