开始我自定义的版本更新框是这样的:

前几天我看见了简书的版本更新的提示框,感觉不错就模仿写了一个
效果图如下:

所以下简单的思路吧:
1.首先请求项目的当前版本信息(boudleid为你自己项目的boudleid)
NSString *storeString = [NSString stringWithFormat:@"https://itunes.apple.com/lookup?bundleId=%@",boudleid];
2.对版本号进行比较,是否弹出提示框

3.至于提示框就很简单了
UIAlertController *alertController=[UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"发现新版本%@",currentVersion] message:releaseNotes preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action0=[UIAlertAction actionWithTitle:@"下次再说" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
UIAlertAction *action1=[UIAlertAction actionWithTitle:@"忽略此版本" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
UIAlertAction *action2=[UIAlertAction actionWithTitle:@"前往更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:trackUrl]];
}];
[alertController addAction:action0];
[alertController addAction:action1];
[alertController addAction:action2];
[self.showController presentViewController:alertController animated:YES completion:nil];
最后在你所要展示的控制器写上一句代码就行了:
[LMUpdateVersionManage checkVersionInController:self];
完事!!
做完之后发现更新的内容提示是居中的,我想了下没想到如何让他居左对齐,回头看了下简书的,发现他也存在这个问题。而我之前做的提示信息,使用的一个tableview来展示的,发现比简书在这方面还是美观一点,项目里面还是用以前的吧^^^.
githubDemo地址:我的github
如果你有好的建议可以告诉我!!!
网友评论