iOS - 利用 iTunes 接口检查 App 版本更新
iOS 想要检查 App 当前版本是否为最新,一般的方案大概都是服务器自己提供一个接口来获取 App 最新版本是多少,然后再做出相应提示是否需要更新,但是接口需要手动维护,应用要审核,还得等审核通过以后才能更新版本号,其实苹果提供了一个 iTunes 接口,能够查到 App 在 AppStore 上的状态信息,既省事又准确,下面记录一下具体实现方法。
接口信息
这是iTunes接口地址 ,有兴趣可以看一下,我们要用到的接口如下,xxx 处换成自己 App 的 AppId ,AppId 可以在 iTunes Connect 里面看到。
http://itunes.apple.com/lookup?id=xxx
接口返回的内容有很多,下面展示一些有用的看看。
{
"resultCount" : ,
"results" : [{
"artistId" : "开发者 ID",
"artistName" : "开发者名称",
"trackCensoredName" : "审查名称",
"trackContentRating" : "评级",
"trackId" : "应用程序 ID",
"trackName" = "应用程序名称",
"trackViewUrl" = "应用程序下载网址",
"userRatingCount" = "用户评论数量",
"userRatingCountForCurrentVersion" = "当前版本的用户评论数量",
"version" = "版本号"
}]
}
实现方法
下面是检查版本更新的具体实现方法,注意接口地址 xxx 处换成自己 App 的 AppId ,App 审核的时候版本肯定是比 AppStore 上高的,所以不用担心审核时会跳出更新提示。
/// 检查版本更新
- (void)checkVersion {
NSString *url = @"http://itunes.apple.com/lookup?id=xxx";
[[AFHTTPSessionManager manager] POST:url parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
DLog(@"版本更新检查成功");
NSArray *results = responseObject[@"results"];
if (results && results.count > ) {
NSDictionary *response = results.firstObject;
NSString *currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; // 软件的当前版本
NSString *lastestVersion = response[@"version"]; // AppStore 上软件的最新版本
if (currentVersion && lastestVersion && ![self isLastestVersion:currentVersion compare:lastestVersion]) {
// 给出提示是否前往 AppStore 更新
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"检测到有版本更新,是否前往 AppStore 更新版本。" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"前往" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSString *trackViewUrl = response[@"trackViewUrl"]; // AppStore 上软件的地址
if (trackViewUrl) {
NSURL *appStoreURL = [NSURL URLWithString:trackViewUrl];
if ([[UIApplication sharedApplication] canOpenURL:appStoreURL]) {
[[UIApplication sharedApplication] openURL:appStoreURL];
}
}
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
[self.window.rootViewController presentViewController:alert animated:YES completion:nil];
}
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
DLog(@"版本更新检查失败");
}];
}
/// 判断是否最新版本号(大于或等于为最新)
- (BOOL)isLastestVersion:(NSString *)currentVersion compare:(NSString *)lastestVersion {
if (currentVersion && lastestVersion) {
// 拆分成数组
NSMutableArray *currentItems = [[currentVersion componentsSeparatedByString:@"."] mutableCopy];
NSMutableArray *lastestItems = [[lastestVersion componentsSeparatedByString:@"."] mutableCopy];
// 如果数量不一样补0
NSInteger currentCount = currentItems.count;
NSInteger lastestCount = lastestItems.count;
if (currentCount != lastestCount) {
NSInteger count = labs(currentCount - lastestCount); // 取绝对值
for (int i = ; i < count; ++i) {
if (currentCount > lastestCount) {
[lastestItems addObject:@""];
} else {
[currentItems addObject:@""];
}
}
}
// 依次比较
BOOL isLastest = YES;
for (int i = ; i < currentItems.count; ++i) {
NSString *currentItem = currentItems[i];
NSString *lastestItem = lastestItems[i];
if (currentItem.integerValue != lastestItem.integerValue) {
isLastest = currentItem.integerValue > lastestItem.integerValue;
break;
}
}
return isLastest;
}
return NO;
}
iOS - 利用 iTunes 接口检查 App 版本更新的更多相关文章
- iOS 检查app版本更新操作
iOS 检查app版本更新操作 1:获取本地安装的版本信息: [NSString stringWithFormat:@"Version %@ (%@)", [[[NSBundle ...
- iOS利用剪切板在app中传递信息
利用iOS剪切板在app中传递信息 App1 中添加URLSchemes app1 App2 中国添加URLSchemes app2 App1中进入app2: UIApplication.sh ...
- Android 6.0 7.0 8.0 一个简单的app内更新版本-okgo app版本更新
登陆时splash初始页调用接口检查app版本.如有更新,使用okGo的文件下载,保存到指定位置,调用Android安装apk. <!-- Android 8.0 (Android O)为了针对 ...
- iOS利用Application Loader打包提交到App Store时遇到错误The filename 未命名.ipa in the package contains an invalid character(s). The valid characters are:A-Z ,a-z,0-9,dash,period,underscore,but the name cannot start w
iOS利用Application Loader打包提交到App Store时遇到错误: The filename 未命名.ipa in the package contains an invalid ...
- App版本更新接口的设计
前段时间公司业务调整,新开了新的移动端的项目,所以和朋友聊到了“版本号”和“版本更新所需的数据表设计”. 一般来讲大部分的软件版本号分3段,比如 A.B.C A 表示大版本号,一般当软件整体重写,或出 ...
- Xamarin.iOS - 利用Settings插件与EAIntroView制作App的欢迎界面
Xamarin.iOS - 利用Settings插件与EAIntroView制作App的欢迎界面 关于欢迎界面 很多App第一次启动都会有一个欢迎界面,欢迎界面往往决定这用户对App的第一映像,所以欢 ...
- iOS利用HealthKit框架从健康app中获取步数信息
微信和QQ的每日步数最近十分火爆,我就想为自己写的项目中添加一个显示每日步数的功能,上网一搜好像并有相关的详细资料,自己动手丰衣足食. 统计步数信息并不需要我们自己去实现,iOS自带的健康app已经为 ...
- 发布iOS应用程序到苹果APP STORE完整流程
参考:http://blog.csdn.net/mad1989/article/details/8167529(xcode APP 打包以及提交apple审核详细流程(新版本更新提交审核)) http ...
- 【百度地图API】如何利用PhoneGap制作地图APP
原文:[百度地图API]如何利用PhoneGap制作地图APP 摘要:百度地图API是一套由javascript编写的地图程序接口,按说它应该运行在浏览器上.现在,只要利用PhoneGap,我们就能开 ...
随机推荐
- mongoose实现批量删除和多id查询的api/方法
删除一条数据:传入id Model.remove({ _id: 传入的id }); 删除多条数据,传入id数组,使用$in方法 Model.remove({ _id: { $in: ['aID', ' ...
- RMAN:简单的duplicate创建新数据库
duplicate to "test" backup location '/home/oracle/11.2.0.4/assistants/dbca/templates/'; du ...
- Thinkphp 模板中使用自定义函数的方法
1.number_format {$number|number_format=2} 千分位,保留两位小数 2.round {$number|round=2} 四舍五入保留两位小数
- kendo-ui的MVVM模式
摘要: MVVM(Model View ViewModel)是一种帮助开发者将数据从模型分离的设计模式.MVVM的ViewModel负责将数据对象从模型中分离出来,通过这种方式数据就很容易控制数据如何 ...
- MsChart,饼状图
HTML 后台代码:(dt为数据源)数据库中数据Sample 1 Chart1.Series["Series1"].Label = "#PERCENT{P}"; ...
- PMP模拟考试-1
1. A manufacturing project has a schedule performance index (SPI) of 0.89 and a cost performance ind ...
- NuGet的几个小技巧(转)
NuGet的几个小技巧 因为可视化库程序包管理器的局限性,有很多需要的功能在界面中无法完成. 以下技巧均需要在“程序包管理器控制台”中使用命令来完成. 一.改变项目目标框架后,更新程序包 当改变项 ...
- Windows系统下运行某些程序时缺少“Msflxgrd.ocx”的解决方法
出现这样的错误就是系统缺少相应的库文件,我们安装即可. 下载Msflxgrd.ocx,这里提供一个下载网址:https://www.ocxme.com/files/msflxgrd_ocx 64位系统 ...
- 使用 vux 框架
1)vux官网:https://vux.li/#/ 2)通过 vue-cli 工具使用 vux 1.如果没有安装 nodejs,请先前往 nodejs 官网下载并安装 nodejs,传送门:https ...
- 3. Oracle数据库逻辑备份与恢复
一. Oracle逻辑备份介绍 Oracle逻辑备份的核心就是复制数据:Oracle提供的逻辑备份与恢复的命令有exp/imp,expdp/impdp.当然像表级复制(create table tab ...