版本记录
版本号 | 时间 |
---|---|
V1.0 | 2017.07.24 |
前言
在app中,app在登录的时候都要进行版本检测,如果有新的版本需要下载就要跳转到appStore进行更新客户端,这一篇就说一下版本检测的方法。感兴趣的可以看看我写的其他小技巧。
1. 实用小技巧(一):UIScrollView中上下左右滚动方向的判断
2. 实用小技巧(二):屏幕横竖屏的判断和相关逻辑
3.实用小技巧(三):点击手势屏蔽子视图的响应
4.实用小技巧(四):动态的增删标签视图
5.实用小技巧(五):通过相册或者相机更改图标
6.实用小技巧(六):打印ios里所有字体
7. 实用小技巧(七):UITableViewCell自适应行高的计算
8. 实用小技巧(八):数字余额显示的分隔
9.实用小技巧(九):类头条模糊背景的实现
10.实用小技巧(十):晃动手机换后台服务器网络
11.实用小技巧(十一):scrollView及其子类显示的一些异常处理
12.实用小技巧(十二):头像图片缩放以及保存到相册简单功能的实现
13.实用小技巧(十三):一种类酷我音乐盒动画实现
14.实用小技巧(十四):生成跳往applestore指定app的方法
15.实用小技巧(十五):左侧向右滑动返回上一级控制器
16.实用小技巧(十六):获取设备信息
17.实用小技巧(十七):清除缓存目录
18.实用小技巧(十八):取出gif图的每一帧
19.实用小技巧(十九):获取相机和麦克风权限
20.实用小技巧(二十):游客模式的实现
功能需求
实现app客户端的版本检测
功能实现
下面我们就看一下app客户端的功能实现。
还是直接看代码吧。
1. JJMainTabBarVC
- (void)viewDidLoad
{
[super viewDidLoad];
self.tabBar.tintColor = [UIColor colorWithHexString:@"#FFB412"];
[self requestVersionCheckAlert];
//默认显示中间vc
[self setSelectedIndex:1];
}
//版本检测方法
- (void) requestVersionCheckAlert
{
AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
if (appDelegate.isCheck) {
return;
}
else {
appDelegate.isCheck = YES;
}
//请求接口,检查版本
[[JJNetWorkManager manager] requestByPostNetworkWithServerUrl:kVersionCheckAlert parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSString *code = [responseObject valueForKey:@"code"];
if (code.integerValue == 0) {
NSDictionary *data = [responseObject valueForKey:@"data"];
NSString *updateType = [data valueForKey:@"updateType"];
if (updateType.integerValue > 0) {
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"版本提示" message:@"检测到新版本,是否立即前往升级?" preferredStyle:UIAlertControllerStyleAlert];
if (updateType.integerValue == 1) {
UIAlertAction *goAction = [UIAlertAction actionWithTitle:@"前往" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSURL *url = [NSURL URLWithString:@"itms-apps://itunes.apple.com/cn/app/id1140440766"];
[[UIApplication sharedApplication] openURL:url];
return;
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
return;
}];
[alertVC addAction:goAction];
[alertVC addAction:cancelAction];
}
else {
UIAlertAction *goAction = [UIAlertAction actionWithTitle:@"前往" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-apps://itunes.apple.com/cn/app/id1140440766"]];
return;
}];
[alertVC addAction:goAction];
}
[self presentViewController:alertVC animated:YES completion:nil];
}
}
} error:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];
}
功能验证
这个不太好验证,需要发布新版本且需要后端同学的配合,这里就不验证了,以前验证过亲测可用,希望对大家有所帮助。
后记
这个估计是我写的文章中最短的一篇,但是这个功能确实很简单也没什么可以写的了,还是希望对大家有所帮助吧。