最近在做更新版本的功能,在做好一切准备后发现一个安全漏洞,如果用户点击取消,返回进入游戏,还是可以继续游戏,但是旧版本的运行会带来很多新问题。
那么就要想到一个方法来使得用户不更新无法进入游戏的效果 - 嵌套的UIAlertView是一个很好的选择。
没有改进前的逻辑代码,很显然的是检查到强更机制后,如果取消,用户仍然可以进行方法: [self activate37SDK] ,则初始化正常,存在漏洞
if (UPDATE_NO_UPDATE == type)
{
LOG(@"没有更新, 已经是最新版本.");
}
else if (UPDATE_NORMAL_UPDATE == type)
{
LOG(@"检查到有版本更新.");
[systemInfo sdkUpdateTypeWithURL:updateurl cancelButtonTitle:@"立即更新" sureButtonTitle:@"稍后更新"];
}
else if (UPDATE_FORCE_UPDATE == type)
{
LOG(@"检查到有强制的版本更新");
[systemInfo sdkUpdateTypeWithURL:updateurl cancelButtonTitle:@"立即更新" sureButtonTitle:nil];
}
[self activate37SDK];
那么怎么样使得用户必须更新呢? 嵌套UIAlertView - 不断地弹出框直到更新!
贴上改进后的代码:
if (UPDATE_NO_UPDATE == type) {
LOG(@"没有更新, 已经是最新版本.");
}
else if (UPDATE_NORMAL_UPDATE == type)
{
LOG(@"检查到有版本更新.");
//弹出更新框操作
[systemInfo sdkUpdateTypeWithURL:updateurl cancelButtonTitle:@"立即更新" sureButtonTitle:@"稍后更新"];
}
else if (UPDATE_FORCE_UPDATE == type)
{
LOG(@"检查到有强制的版本更新");
//添加参数:强制更新的地址,以方便alertView代理方法使用
self.forceUpDateUrl = updateurl;
//因为和alertView存在异步执行,所以定义线程执行方法完毕后进行下一操作
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group, dispatch_get_main_queue(), ^{
[systemInfo sdkUpdateTypeWithURL:updateurl cancelButtonTitle:@"立即更新" sureButtonTitle:nil];
});
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@""
message:@"必须升级的哦"
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:nil, nil];
[alert show];
}
[self activate37SDK];
代理方法嵌套UIAlertView:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group, dispatch_get_main_queue(), ^{
[[SYSystemInfo shareSystemInfo] sdkUpdateTypeWithURL:self.forceUpDateUrl cancelButtonTitle:@"立即更新" sureButtonTitle:nil];
});
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"必须更新"
message:nil
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:nil, nil];
[alert show];
}
改进之后,进入游戏,提醒更新,点击跳转更新,如果取消安装,回到游戏
总结:这种方法的实现不难,但是一定要充分了解业务逻辑,清楚业务逻辑之后才能知道升级之后会把这个逻辑消除
第二:懂得代理嵌套代理的循环使用
第三:防止异步进程的问题
如果以后有别的方法会添上!