我们知道 苹果已经不允许APP内置栏目提醒用户升级当前版本,但是我们仍然可以使用进去应用弹窗的方式来曲线提醒用户及时升级到最新版本的APP。
+(NSString *)getCurrentAppVersion{
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];//CFBundleVersion
return currentVersion;
NSDictionary *dict = result.returndata;
if (isShowVersion) {//设置BOOL 进入应用后确保只调用一次接口刷新。
NSString *updateFlag = [dict objectForKey:@"updateFlag"];
if (updateFlag!=nil&&![updateFlag isEqualToString:@"false"]) {
NSString *newVersion = [dict objectForKey:@"versionCode"];
NSString *updateType = [dict objectForKey:@"updateType"];
NSString *description = [dict objectForKey:@"description"];
_downloadUrl = [dict objectForKey:@"updateUrl"];
_content = description;
if (updateType!=nil&&(NSNull *)updateType!=[NSNull null]&&[updateType isEqualToString:@"forced"]) {
[self versionConfirm];//不支持旧版本,直接跳转APPstore页面更新
return;
} else {
[self showVersionAlert];//支持当前版本,但是有新的更新 显示弹窗页面
}
}
}
isShowVersion = NO;//关闭标示符,不再调用该接口
}
} andVersion:currentVersion andAppType:@"ios"];
}
- (void)showVersionAlert {
_versionMaskingView.backgroundColor = [UIColor blackColor];
_versionMaskingView.alpha = 0.7;
[window addSubview:_versionMaskingView];
UIWindow *window = [ UIApplication sharedApplication ]. keyWindow ;......
//动效
__block UIView *versionView = _versionView;
__block UIView *tempMaskView = _versionMaskingView;
[UIView animateWithDuration:0.6 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
versionView.transform = CGAffineTransformIdentity;
versionView.alpha = 1;
tempMaskView.alpha = 0.4;
} completion:nil];
//关闭弹窗更新
-(void)versionClose {
__block UIView *tempMaskView = _versionMaskingView;
__block UIView *versionView = _versionView;
[UIView animateWithDuration:0.6 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
versionView.transform = CGAffineTransformMakeScale(1.5, 1.5);
versionView.alpha = 0;
tempMaskView.alpha = 0;
} completion:^(BOOL finished) {
[tempMaskView removeFromSuperview];
tempMaskView = nil;
[versionView removeFromSuperview];
versionView = nil;
}];
}
//跳转APPstore页面更新
-(void)versionConfirm {
[self versionClose];
NSURL *url = [NSURL URLWithString:_downloadUrl];
[[UIApplication sharedApplication]openURL:url];
}