蒲公英App开发之检测新版本
https://www.jianshu.com/p/2d3f048511d7
2017.04.17 16:22* 字数 62 阅读 422评论 0喜欢 1
可以在App内部实现检测版本更新并实现安装。
核心代码
#define API_PGYER_UPDATE_URL @"https://www.pgyer.com/apiv1/app/builds"
#define PGY_API_KEY @""
#define PGY_APP_ID @""
- (void)checkForUpdates {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSDictionary *parameters = @{@"aId":PGY_APP_ID,@"page":@1,@"_api_key":PGY_API_KEY};
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] requestWithMethod:@"POST" URLString:API_PGYER_UPDATE_URL parameters:parameters error:nil];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
MJWeakSelf
NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
return;
}
NSLog(@"%@ %@", response, responseObject);
if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
NSDictionary *responseDictionary = (NSDictionary *)responseObject;
if (responseDictionary && [responseDictionary objectForKey:@"data"]) {
NSDictionary *data = [responseDictionary objectForKey:@"data"];
if (!data || data.count == 0) {
return;
}
NSArray *array = [data objectForKey:@"list"];
if (array) {
BFLarkAppDeatilModel *appDeatil = [BFLarkAppDeatilModel mj_objectArrayWithKeyValuesArray:array].firstObject;
if (appDeatil) {
// 有新版本
if (appDeatil.appVersionNo.integerValue > [[[UIApplication sharedApplication] appBuildVersion] integerValue]) {
dispatch_async(dispatch_get_main_queue(), ^{
[BFAlertView showAlertInViewController:weakSelf.view withTitle:[NSString stringWithFormat:@"Current BuildVersion %@, New BuildVersion %@",[[UIApplication sharedApplication] appBuildVersion],appDeatil.appVersionNo] message:@"旧版就像初恋,很美但再也回不去,快去收获新欢" cancelButtonTitle:@"取消" destructiveButtonTitle:@"残忍拒绝" otherButtonTitles:@[@"欣然前往"] tapBlock:^(RMUniversalAlert * _Nonnull alert, NSInteger buttonIndex) {
// 去更新
if (buttonIndex == 2) {
NSString *urlString = [NSString stringWithFormat:@"itms-services://?action=download-manifest&url=https://www.pgyer.com/app/plist/%@",appDeatil.appKey];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}
}];
});
}
// 当前是最新版本
else {
dispatch_async(dispatch_get_main_queue(), ^{
// 更新界面
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您的版本是最新的" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show];
});
}
}
}
}
}
}];
[dataTask resume];
});
}
BFLarkAppDeatilModel
#import <Foundation/Foundation.h>
@interface BFLarkAppDeatilModel : NSObject
@property (nonatomic, copy) NSString *appKey;
@property (nonatomic, copy) NSString *appVersion;
@property (nonatomic, copy) NSString *appBuildVersion;
@property (nonatomic, copy) NSString *appName;
@property (nonatomic, copy) NSString *appIcon;
@property (nonatomic, copy) NSString *appCreated;
@property (nonatomic, copy) NSString *appFileSize;
@property (nonatomic, copy) NSString *appIdentifier;
@property (nonatomic, copy) NSString *appType;
@property (nonatomic, copy) NSString *appVersionNo;
@end
API详解
获取App所有版本
API地址
POST http://www.pgyer.com/apiv1/app/builds
POST参数
|
参数 |
类型 |
说明 |
|
aId |
String |
App Id |
|
page |
Integer |
历史版本分页页数 |
|
_api_key |
String |
API Key |
返回数据
|
返回参数 |
类型 |
说明 |
|
appKey |
String |
返回应用最新build的App Key |
|
appType |
Integer |
应用类型(1:iOS; 2:Android |
|
appFileSize |
Integer |
App 文件大小 |
|
appName |
String |
应用名称 |
|
appVersion |
String |
版本号 |
|
appVersionNo |
Integer |
适用于Android的版本编号,iOS始终为0 |
|
appBuildVersion |
Integer |
蒲公英生成的用于区分历史版本的build号 |
|
appIdentifier |
String |
应用程序包名,iOS为BundleId,Android为包名 |
|
appIcon |
String |
应用的Icon图标key,访问地址为 http://o1wh05aeh.qnssl.com/image/view/app_icons/[应用的Icon图标key] |
|
appCreated |
String |
应用上传时间 |
参考文档
蒲公英App开发之检测新版本的更多相关文章
- 云如何让App开发更简单?
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 互联网"下半场",移动App开发对于质量.速度的要求更加苛刻.4月初,腾讯云正式上线移动开发平台MobileLine,借 ...
- SharePoint Server 2013开发之旅(二):使用在线的开发人员网站进行SharePoint App开发
上一篇我已经介绍了新版本的SharePoint Server提供了四种主要的开发场景,其中一个全新的App开发模型让我们眼前一亮.这一篇我将介绍如何在线进行SharePoint App开发. 谈到Sh ...
- App开发的过程
直播App开发的过程 第一步:分解直播App的功能,我们以X客为例 视频直播功能,这是一款直播App最主要的功能,要能支持视频直播RTMP推流,使画面传输流畅.清晰(美颜后的清晰,你懂的聊天功能,用户 ...
- 5+ App开发入门指南
HTML5 Plus应用概述 HTML5 Plus移动App,简称5+App,是一种基于HTML.JS.CSS编写的运行于手机端的App,这种App可以通过扩展的JS API任意调用手机的原生能力,实 ...
- App开发到App Store上架,发布流程。
http://blog.csdn.net/wojsg001/article/details/12005887 App开发到App Store上架,发布流程. 分类: IOS2013-09-25 11 ...
- 微信公众平台开发:Web App开发入门
WebApp与Native App有何区别呢?Native App:1.开发成本非常大.一般使用的开发语言为JAVA.C++.Objective-C.2.更新体验较差.同时也比较麻烦.每一次发布新的版 ...
- 分享一下一款直播App开发的过程
听说有人声称开发一款直播App不仅耗时还非常昂贵,今天跟大家说道一下,开发一款直播App到底分几步走? 第一步:分解直播App的功能,我们以X客为例 视频直播功能,这是一款直播App最主要的功能,要能 ...
- 十大技巧快速提升原生APP开发性能
移动应用市场用户争夺战日益激烈,原来做APP拼想法拼创意拼是否抓住用户痛点.现在,精细化用户体验成为了一个APP能否留存用户的关键问题,一旦用户觉得体验不畅,马上就有竞品APP后补,如何开发高性能的移 ...
- WeX5是主要进行app开发吗?能开发微信App吗?
WeX5是一款html5开发工具,可以进行app开发,做出各种H5 App,同样也可以进行主要运行在PC的html5产品,. WeX5开发的应用,不仅可以在微信上运行,也可以直接手机浏览器运行,或者打 ...
随机推荐
- hive笔记:时间格式的统一
一.string类型,年月日部分包含的时间统一格式: 原数据格式(时间字段为string类型) 取数时间和格式的语法 2018-11-01 00:12:49.0 substr(regexp_repl ...
- Incorrect key file for table错误解决方法
问题现象: alter table portal_app_xxxx_xxx add devno varchar(64) NOT NULL DEFAULT '' COMMENT '设备机编',add s ...
- python中的猴子补丁Monkey Patch
python中的猴子补丁Monkey Patch 什么是猴子补丁 the term monkey patch only refers to dynamic modifications of a cla ...
- 下载Eclipse、下载Java各个版本,来这里就对了
Eclipse官网:http://www.eclipse.org/ 不信你去看看 Java官网:https://www.java.com/ 不信你去看看 可惜是,每次进入官网提示都是下面这样的:来,我 ...
- 获取自定义data的几种属性
//获取data属性的几种方法 var id = this.getAttribute('data-id'); var id = $(this).attr('data-id'); var id = $( ...
- (转)Spring Boot 2(一):【重磅】Spring Boot 2.0权威发布
http://www.ityouknow.com/springboot/2018/03/01/spring-boot-2.0.html 就在今天Spring Boot2.0.0.RELEASE正式发布 ...
- vuejs2+webpack2+vuxui2多页面架手脚,支持二级目录
const UglifyJsPlugin = require('uglifyjs-webpack-plugin') // 去console插件 const CompressionWebpackPlug ...
- 2883 -- 【TJOI2018】游园会
Description 小豆参加了\(NOI\)的游园会,会场上每完成一个项目就会获得一个奖章,奖章只会是\(N,O,I\)的字样.在会场.上他收集到了\(K\)个奖章组成的串.兑奖规则是奖章串和兑奖 ...
- 微信小程序接入,https服务器搭建和调试
在进行小程序开发时候,调试时候,希望在本地搭建一个https环境. 准备条件: 1.公网主机(阿里云或者腾讯云主机) 2外网访问工具natapp 步骤: 1.在主机上安装nginx(nginx转发到n ...
- 使用pkg打包Node.js应用的方法步骤
Node.js应用不需要经过编译过程,可以直接把源代码拷贝到部署机上执行,确实比C++.Java这类编译型应用部署方便.然而,Node.js应用执行需要有运行环境,意味着你需要先在部署机器上安装Nod ...