[版本更新提示]

-(void)checkVersion

{

//每天进行一次版本判断

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

[formatter setDateFormat:@"yyyy-MM-dd"];

//获取年-月-日

NSString *dateString = [formatter stringFromDate:[NSDate date]];

NSString *currentDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"currentDate"];

if ([currentDate isEqualToString:dateString]) {

return;

}

[[NSUserDefaults standardUserDefaults] setObject:dateString forKey:@"currentDate"];

NSString *newVersion;

NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/cn/lookup?id=1139094792"];//这个URL地址是该app在iTunes connect里面的相关配置信息。其中id是该app在app store唯一的ID编号。

NSString *jsonResponseString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];

NSLog(@"通过appStore获取的数据信息:%@",jsonResponseString);

NSData *data = [jsonResponseString dataUsingEncoding:NSUTF8StringEncoding];

//    解析json数据

id json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];

NSArray *array = json[@"results"];

for (NSDictionary *dic in array) {

newVersion = [dic valueForKey:@"version"];

}

NSLog(@"通过appStore获取的版本号是:%@",newVersion);

//获取本地软件的版本号

NSString *localVersion = [[[NSBundle mainBundle]infoDictionary] objectForKey:@"CFBundleVersion"];

NSString *msg = [NSString stringWithFormat:@"您的App不是最新版本,请问是否更新"];

//对比发现的新版本和本地的版本

if ([newVersion floatValue] > [localVersion floatValue])

{

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"更新提示"message:msg preferredStyle:UIAlertControllerStyleAlert];

[self presentViewController:alert animated:YES completion:nil];

[alert addAction:[UIAlertAction actionWithTitle:@"现在更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/yi-ka-tongbic-ban/id1139094792?l=en&mt=8"]];

//这里写的URL地址是该app在app store里面的下载链接地址,其中ID是该app在app store对应的唯一的ID编号。

NSLog(@"点击现在升级按钮");

}]];

[alert addAction:[UIAlertAction actionWithTitle:@"下次再说" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

NSLog(@"点击下次再说按钮");

}]];

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • //版本检查 (void)checkAppVersion{AFHTTPSessionManager * manag...
    xieyinghao阅读 431评论 0 0
  • 用到版本更新,首先现在网络上搜了搜发现没有满意的,于是参考一个 重写了一下,支持1.1.1.1.2这种的 版本判断...
    谁在呼叫贱队阅读 1,094评论 0 0
  • 王连山冷敷贴是一种外用贴膏,现在这种贴膏在市面上是有很多的,贴膏的药性方面也是良好。虽然如此,很多人们就会担心贴膏...
    377f8bc62adf阅读 803评论 1 0
  • 《静静的时光》 静静的时光干净,处山峦深处,四边拥绿,阳光细致,正是初夏的日子。 早上...
    合肥张建春阅读 360评论 0 5
  • 这个世界 有孤傲的月 不愿融化的冰 和遥不可及的你。
    素凝阅读 225评论 0 3