美文网首页
iOS 版本更新

iOS 版本更新

作者: 雪丹妮_66865 | 来源:发表于2018-09-30 16:57 被阅读8次
    1. 获取本机版本号

    NSDictionary *localDic = [[NSBundle mainBundle] infoDictionary];
    NSString *localVersions = [localDic objectForKey:@"CFBundleShortVersionString"];

    1. 查看appstore中的软件最新版本

    地址:https://itunes.apple.com/lookup?id=软件的apple Id

    NSArray *resultArr = responseObject[@"results"];
    NSDictionary *resultDic = resultArr.firstObject;
    NSString *latestVersion = resultDic[@"version"];

    1. 如果版本不一致,进行更新

    if ([latestVersion compare:localVersions options:NSNumericSearch] == NSOrderedDescending) {
    [self updateBtnActionwithLatestVersion:latestVersion];
    }

    • (void)updateBtnActionwithLatestVersion:(NSString *)latestVersion {
      UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"检查到最新版本" message:latestVersion preferredStyle:UIAlertControllerStyleAlert];
      UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

      }];
      UIAlertAction *updateAction = [UIAlertAction actionWithTitle:@"下载" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
      UIApplication *application = [UIApplication sharedApplication];
      [application openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/id软件的Apple id"]];
      }];
      [alertController addAction:cancelAction];
      [alertController addAction:updateAction];
      [self presentViewController:alertController animated:YES completion:nil];
      }

    相关文章

      网友评论

          本文标题:iOS 版本更新

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