美文网首页iOS常用
ios 检测更新

ios 检测更新

作者: 肉肉要次肉 | 来源:发表于2020-06-22 15:00 被阅读0次

Git地址:https://github.com/wolfhous/HSUpdateApp

1、将这文件拖入你的工程中,在appdelegate中调用检测

2、引入头文件 #import "HSUpdateApp.h"

3、

[HSUpdateApp hs_updateWithAPPID:@"1492599319" withBundleId:nil block:^(NSString *currentVersion, NSString *storeVersion, NSString *openUrl, BOOL isUpdate) {

        SLog(@"appdelegate: 本地:%@,商店:%@",currentVersion,storeVersion);

            if (isUpdate) {

                [self showAlertViewTitle:@"有更新" subTitle:[NSString stringWithFormat:@"检测到新版本%@,是否更新?",storeVersion] openUrl:openUrl];

           }else{

                NSLog(@"当前版本%@,商店版本%@,不需要更新",currentVersion,storeVersion);

            }

 }];

-(void)showAlertViewTitle:(NSString*)titlesubTitle:(NSString*)subTitleopenUrl:(NSString*)openUrl{

    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:subTitle preferredStyle:UIAlertControllerStyleAlert];

    NSLog(@"hhh:%@",openUrl);

    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        if([[UIDevice currentDevice].systemVersion floatValue] >= 10.0){

            if([[UIApplicationsharedApplication]respondsToSelector:@selector(openURL:options:completionHandler:)]) {

                if(@available(iOS10.0, *)) {

                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:openUrl] options:@{} completionHandler:^(BOOL success) {

                    }];

                }else{

                    // Fallback on earlier versions

                }

            }else{

                BOOLsuccess = [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:openUrl]];

                NSLog(@"Open  %d",success);

            }

        }else{

            bool can = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:openUrl]];

            if(can){

                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:openUrl]];

            }

        }

    }];

    [alertVCaddAction:sure];

    [self.window.rootViewController presentViewController:alertVC animated:YES completion:nil];

}

以上就是通过从appstore中获取到最新的app版本号跟用户本地的版本号去做对比,以此来判断是否弹窗提示用户去跳转到appstore进行更新。

但是有一个缺点就是appstore更新的进度往往会有延迟,相同的app,用户手机的appstore不一定同一时间更新出最新的版本号。

如果有希望可以第一时间提示用户更新的话,就通过自己服务器来返回版本号会更及时。

相关文章

  • iOS检测更新

    原理: 通过appid访问 http://itunes.apple.com/lookup 可以获取appStore...

  • ios 检测更新

    Git地址:https://github.com/wolfhous/HSUpdateApp 1、将这文件拖入你的工...

  • iOS检测版本更新

    利用iTunes接口检查App版本更新

  • iOS 检测版本更新

  • iOS检测版本更新

    效果图 具体实现代码参考源码https://github.com/wolfhous/HSUpdateApp 文件小...

  • iOS 版本检测更新

  • iOS 检测版本更新

    在苹果的 app store 条文中,是不允许新版本提示的, 但是只要不让那些审核员知道有这个功能就可以了。启动的...

  • iOS检测更新APP

    iOS APP检查更新有两种方法: 1、在某特定的服务器上,发布和存储app最新的版本信息,需要的时候向该服务器请...

  • iOS 检测版本更新

    基于良好的用户体验,当在appStroe上线了新的版本时,提醒用户更新”新版本“是必不可少的。 版本更新的...

  • iOS App检测更新

    // 1. 获取App的版本 NSDictionary *infoDic = [[NSBundle mainBun...

网友评论

    本文标题:ios 检测更新

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