版本更新管理
来源:互联网 发布:centos 6.5 安装php7 编辑:程序博客网 时间:2024/06/14 20:50
单例封装了一个版本更新管理类
UI效果:
+ (instancetype)sharedInstance {
static UpdateVersionManage *sharedInstance =nil;
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
- (void)setIsHaveIgnoreUP:(BOOL)isHaveIgnoreUP{
_isHaveIgnoreUP = isHaveIgnoreUP;
}
-(instancetype)init{
self=[superinit];
if (self) {
__weak typeof(self) weakSelf=self;
self.updateBlock = ^(NSString *currentVersion ,NSString *releaseNotes,NSString *trackUrl, NSString *type){
__strong typeof(self) strongSelf=weakSelf;
[strongSelf showUpdateViewWith:(NSString *)currentVersionwith:(NSString *)releaseNoteswith:(NSString *)trackUrlwith:type];
};
}
return self;
}
#pragma mark--版本更新--1表示不需要更新,2选择更新,3强制更新
+(void)checkVersionInController:(UIViewController *)showController{
#pragma mark--type --网络请求获得type值,根据业务处理
NSString *type = @"3";
if ([typeisEqualToString:@"2"])
{//有更新,当前版本可用
if ([UpdateVersionManagesharedInstance].isHaveIgnoreUP ==YES) {
return ;
}
[UpdateVersionManagesharedInstance].showController = showController;
[UpdateVersionManagesharedInstance].isHaveIgnoreUP =YES;
if ([UpdateVersionManagesharedInstance].updateBlock) {
[UpdateVersionManagesharedInstance].updateBlock(@"更新内容",@"优化了哪些内容",@"下载链接",type);
}
}
else if ([typeisEqualToString:@"3"])//强制更新
{
[UpdateVersionManagesharedInstance].showController = showController;
if ([UpdateVersionManagesharedInstance].updateBlock) {
[UpdateVersionManagesharedInstance].updateBlock(@"更新内容",@"优化了哪些内容",@"下载链接",type);
}
}
}
#pragma mark - 更新界面
-(void)showUpdateViewWith:(NSString *)currentVersion with:(NSString *)releaseNotes with:(NSString *)trackUrl with:(NSString *)type{
if ([typeisEqualToString:@"2"])
{
[self showIgnoreUpdateViewWith:currentVersionwith:releaseNoteswith:trackUrl];
}else if ([typeisEqualToString:@"3"])
{
[self showMustUpdateViewWith:currentVersionwith:releaseNoteswith:trackUrl];
}
}
-(void)showIgnoreUpdateViewWith:(NSString *)currentVersion with:(NSString *)releaseNotes with:(NSString *)trackUrl{
UIAlertController *alertController=[UIAlertControlleralertControllerWithTitle:[NSStringstringWithFormat:@"发现新版本%@",currentVersion] message:releaseNotespreferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action1=[UIAlertActionactionWithTitle:@"下次再说" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) {
}];
UIAlertAction *action2=[UIAlertActionactionWithTitle:@"前往更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) {
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:[trackUrlstringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSetURLQueryAllowedCharacterSet]]]];
}];
[alertController addAction:action1];
[alertController addAction:action2];
if ([UpdateVersionManagesharedInstance].showController) {
[[UpdateVersionManagesharedInstance].showControllerpresentViewController:alertControlleranimated:YEScompletion:nil];
}else
{
[[UpdateVersionManagegetCurrentVC]presentViewController:alertControlleranimated:YEScompletion:nil];
}
}
-(void)showMustUpdateViewWith:(NSString *)currentVersion with:(NSString *)releaseNotes with:(NSString *)trackUrl{
UIAlertController *alertController=[UIAlertControlleralertControllerWithTitle:[NSStringstringWithFormat:@"发现新版本%@",currentVersion] message:releaseNotespreferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action2=[UIAlertActionactionWithTitle:@"前往更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) {
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:[trackUrlstringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSetURLQueryAllowedCharacterSet]]]];
}];
[alertController addAction:action2];
if ([UpdateVersionManagesharedInstance].showController) {
[[UpdateVersionManagesharedInstance].showControllerpresentViewController:alertControlleranimated:YEScompletion:nil];
}else
{
[[UpdateVersionManagegetCurrentVC]presentViewController:alertControlleranimated:YEScompletion:nil];
}
}
Git地址demo
iOS版本管理
- 版本更新管理
- 对版本更新的管理
- 对于unity3d 对于热更新的思考!!!(版本管理)
- 版本更新
- //版本更新
- 版本更新
- 更新版本
- 版本更新
- 版本更新
- 版本更新
- 版本更新
- 版本更新
- 版本更新
- 版本更新
- 版本更新
- 版本更新
- 版本更新
- 版本更新
- 安卓ImageView的几种资源调用方法
- 单词表示数字-LintCode
- 227. Basic Calculator II
- 深入理解Java内存模型(六)——final
- 短信轰炸机
- 版本更新管理
- java设计模式
- 微信开放实战--扫一扫功能(详细)
- SpringBoot初窥:application.properties配置
- 251. Flatten 2D Vector
- 线性代数的本质与几何意义 01. 向量是什么?(3blue1brown 咪博士 图文注解版)
- 扑克牌的顺子
- 12.1Groovy使用GroovyInterceptable拦截方法
- 助你快速踏入高薪职场——2017面试集锦之html & JavaScript & ajax