iOS检测版本更新

来源:互联网 发布:乐敦美白淡斑精华知乎 编辑:程序博客网 时间:2024/06/07 10:12


项目介绍:

具体实现代码参考源码https://github.com/wolfhous/HSUpdateApp

文件小巧,轻便:

只有一个.h和.m文件.png

支持cocoapods:

pod 'HSUpdateApp'

用法:

#import "HSUpdateApp.h"
/**   一行代码实现检测app是否为最新版本。appId,bundelId,随便传一个 或者都传nil 即可实现检测。  @param currentVersion 返回当前版本号  @param storeVersion 返回商店版本号  @param openUrl 跳转到商店下载的链接  @param isUpdate 是否需要更新  @return */ [HSUpdateApp hs_updateWithAPPID:nil withBundleId:nil block:^(NSString *currentVersion, NSString *storeVersion, NSString *openUrl, BOOL isUpdate) {  }];

问题1:这样审核能通过?

答1:亲测能通过,没问题的。


问题2:我项目APP ID 在哪里看?

答2:itunes connect 》我的APP》APP ID


问题3:假如我的项目还没上线,也没有APP ID 怎么搞?

答3:
--直接利用自动检测,appId和bundelId都传nil即可。
--或者去 itunes connect 申请一个APP,就会有对应的APP ID。
--如果你连开发者账号都没有,那就先用demo里面的APP ID 测试吧,上线的时候改过来即可。




实现思路

1.本地检测项目版本号;

NSDictionary *infoDic=[[NSBundle mainBundle] infoDictionary];NSString *currentVersion=infoDic[@"CFBundleShortVersionString"];

2.联网检测项目在AppStore上的版本号;

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@",appId]]];NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {}];[task resume];

3.比较版本号,可选提供跳转到手机自带的AppStore项目页面供用户下载的地址;
https://itunes.apple.com/us/app/id1104867082?ls=1&mt=8




下载该GitHub源码请点我

原创粉丝点击