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,我们就能开 ...
随机推荐
- python-类的方法与类的成员
preface include: @classmethod @staticmethod @property 私有属性 类的成员 #!/usr/bin/env python class animal(o ...
- JavaScript实现最简单的拖拽效果
一.一些无关痛痒的唠叨 拖拽还是挺不错的一个页面效果,我个人认为,其生命力在于可以让用户自己做一些操作,所谓自定义.例如: ①浏览器标签顺序的拖拽切换 现在基本上所有的选项卡式的浏览器都有顺序拖拽切换 ...
- myeclipse安装jad反编译插件
有时候想深入底层看jar包封装的源代码,但是打不开.这就需要配置反编译插件: 1:准备原材料 jad.exe + net.sf.jadclipse_3.3.0.jar 下载目录: jad.exe : ...
- linux 安装 Django 安装
下载源码包:https://www.djangoproject.com/download/ 输入以下命令并安装: tar xzvf Django-X.Y.tar.gz # 解压下载包 cd Djang ...
- JSON未定义
用ajax实现了一个功能,在IE8和IE9中都能正常运行(大概是IE8和IE9都提供了原生的JSON解析和序列化),但是一旦切换到兼容模式就报JSON未定义的错误,解决方法是:判断当前浏览器是否支持J ...
- linux 实时查看Tomcat日志信息
cd /../tomcat/logs 进入tomcat/logs/文件夹下 # tail -f catalina.out
- oracle sqlplus常用命令大全
show和set命令是两条用于维护SQL*Plus系统变量的命令 SQL> show all --查看所有68个系统变量值 SQL> show user --显示当前连接用户 SQL> ...
- iOS - 解决Unable to add a source with url `https://github.com/CocoaPods/Specs.git` named
1 本来cocopods没有问题,最近创建项目,利用cocopods导入第三方库的时候,出现如下错误: [!] Unable to add a source with url `https://gi ...
- AcceptEx 以及 获取远程IP与port
// 獲取本地以及遠程的IP和port setsockopt(clientfd, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, (char *)&listenfd ...
- win10进入到安全模式的三种方法
这里介绍三种方法: 如果能够进入到系统 点击开始--设置--更新和安全--恢复,右侧点击高级启动中的立即重启 能够进入到登陆界面 进入到登录屏幕后,在按住 Shift 键的同时依次选择“电源” > ...