美文网首页
iOS 开发_应用更新提示

iOS 开发_应用更新提示

作者: iOS_PM_WEB_尛鹏 | 来源:发表于2017-04-18 11:54 被阅读0次

    【作者前言】:13年入圈,分享些本人工作中遇到的点点滴滴那些事儿,17年刚开始写博客,高手勿喷!以分享交流为主,欢迎各路豪杰点评改进!

    1.应用场景:

    Paste_Image.png

    2.实现目标:

    苹果审核规则里已经明确规定不允许 出现如下按钮,因为APPStore会自动更新

    版本更新
    

    但是因为某些项目要求,在需要更新的时候就需要我们弹窗提示一下,原理很简单,就是先获取APPStore对应产品的版本信息,与用户所安装的版本信息就行对比,如果APPStore版本信息高于用户当前使用的版本,则给出弹窗提示信息

    3.代码说明:

    Tips:获取App Store上产品对应的APPID,如图所示

    Paste_Image.png
    #pragma mark -
    #pragma mark - yp_checkoutUpdateAppVersion 校验是否需要前往APPStore更新
    const NSString *appStoreAppID = @"414478124";//AppStore上面对应的APPID,获取方式如上图
    - (void)yp_checkoutUpdateAppVersion {
        NSString *getAppStoreInfo = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",appStoreAppID];
        //用AFNetwork网络请求方式发起Post请求
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        [manager POST:getAppStoreInfo parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            NSArray *resultsArr = responseObject[@"results"];
            NSDictionary *dict = [resultsArr lastObject];
            /**  得到AppStore的应用的版本信息*/
            NSString *appStoreCurrentVersion = dict[@"version"];
            /**  获取当前安装的应用的版本信息*/
            NSString *appCurrentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
            if ([appCurrentVersion compare:appStoreCurrentVersion options:NSNumericSearch] == NSOrderedAscending){//有更新版本,需要提示前往更新
                UIAlertView *updateAlertV = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"您有新版本更新(%@)", appStoreCurrentVersion] message:@"" delegate:self cancelButtonTitle:@"我在看看" otherButtonTitles:@"马上更新", nil];
                [updateAlertV show];
            }else{//没有更新版本,不进行操作
                NSLog(@"当前为最新版本,暂无更新版本");
            }
    
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
        }];
        
    }
    
    #pragma mark -
    #pragma mark - UIAlertViewDelegate
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
        NSString *updateUrlString = [NSString stringWithFormat:@"https://itunes.apple.com/cn/app/id%@?mt=8",appStoreAppID];
        if (buttonIndex) {//马上更新
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:updateUrlString]];
        }else {//我在看看
            
        }
    }
    

    相关文章

      网友评论

          本文标题:iOS 开发_应用更新提示

          本文链接:https://www.haomeiwen.com/subject/ncsfzttx.html