美文网首页
[版本更新提示]

[版本更新提示]

作者: wo一人两袖清风 | 来源:发表于2017-07-24 10:29 被阅读0次

-(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(@"点击下次再说按钮");

}]];

}

}

相关文章

  • 无标题文章

    //提示版本更新 [self VersonUpdate]; #pragma mark ------提示用户版本更新...

  • [版本更新提示]

    -(void)checkVersion { //每天进行一次版本判断 NSDateFormatter *forma...

  • 版本更新提示

  • 菜鸟教程——实现一句代码实现app更新检测

    版本更新提示是app必备功能,它可以有效提示用户更新。常用的更新提示无非有两种。一种是从苹果api获取版本信息,提...

  • iOS版本更新提示

    iOS更新提示比较简单,不需要后台记录版本号,直接去App Store获取最新版本即可。

  • 提示app 版本更新

    开发中我们可能会遇到这样的需求,当AppStore中有新版本迭代更新,在用户点开APP的时候弹框提醒客户去AppS...

  • app提示版本更新

    下面的 sender[@"version"] 就是获取的版本号 注意是String类型的 2 . 比较appSto...

  • APP版本更新提示

    本文将针对APP新版本提示为大家介绍两种方法,第一种方法是针对已将上线的APP,第二种针对没有上线的APP. 方式...

  • iOS 版本更新提示

    项目需求:由于公司项目是做离线地图的,老板希望有版本更新时用户能及时更新,所以要求app第一次检测到版本更新时记录...

  • ios 版本更新提示

    苹果审核中如果发现项目中有版本更新提示,将禁止上架,那么我们可以让后台传一个字段,上架前后修改一下即可,或者通过下...

网友评论

      本文标题:[版本更新提示]

      本文链接:https://www.haomeiwen.com/subject/wsovkxtx.html