iOS-App版本更新提示

作者: BestVast | 来源:发表于2017-02-11 15:00 被阅读6231次

下面两个接口都可以获取相同的数据,就是App的各种信息

https://itunes.apple.com/cn/lookup?id=AppleID ,为您的 App 自动生成的 ID.
https://itunes.apple.com/cn/lookup?bundleId=app的Bundle Identifier
屏幕快照.png

下面为接口中获取App的各种信息,对应的值仅为个人对比猜测,看看就好

{
 "resultCount":1,
 "results": [
                {"artistViewUrl":"AppStore中,开发人员其他App",
                 "artworkUrl60":"App的icon缩略图60x60大小", 
                 "artworkUrl100":"App的icon缩略图100x100大小", 
                 "ipadScreenshotUrls":[], 
                 "appletvScreenshotUrls":[], 
                 "artworkUrl512":"App的icon图512x512大小", 
                 "isGameCenterEnabled":false, 
                 "kind":"software", 
                 "features":[], 
                 "supportedDevices":["iPhone4S", 
                                    "iPhone5", 
                                    "iPodTouchFifthGen", 
                                    "iPhone5c", 
                                    "iPhone5s", 
                                    "iPhone6", 
                                    "iPhone6Plus", 
                                    "iPodTouchSixthGen"], //适配的手机型号
                 "advisories":[], 
                 "screenshotUrls":["屏幕快照1", 
                                  "屏幕快照2", 
                                  "屏幕快照3"...], 
                                  "trackCensoredName":"App名称-AppStore中显示的名称", 
                                  "trackViewUrl":"App下载地址", 
                                  "contentAdvisoryRating":"4+", 
                                  "fileSizeBytes":"上传时的文件大小", 
                                  "languageCodesISO2A":["主要语言"], 
                                  "sellerUrl":"AppStore中,开发人员网站", 
                                  "trackContentRating":"4+", 
                                  "minimumOsVersion":"AppStore中,兼容性", 
                                  "currency":"CNY", 
                                  "wrapperType":"software", 
                                  "version":"版本号", 
                                  "artistId":1006567848, 
                                  "artistName":"AppStore中,开发商", 
                                  "genres":["分类1", "分类2"...],//上架App时所选 ,最能准确描述此 App 的类别。
                                  "price":0.00, 
                                  "description":"App描述", 
                                  "trackId":"Apple ID ,为您的 App 自动生成的 ID。", 
                                  "trackName":"App名称-Display Name", 
                                  "bundleId":"Bundle Identifier", 
                                  "releaseDate":"App上架时间", 
                                  "primaryGenreName":"Medical", 
                                  "isVppDeviceBasedLicensingEnabled":true, 
                                  "currentVersionReleaseDate":"AppStore中,更新日期", 
                                  "formattedPrice":"免费", 
                                  "releaseNotes":"AppStore中,最新动态", 
                                  "sellerName":"开发商", 
                                  "primaryGenreId":6020, 
                                  "genreIds":["6020", "6013"]
                }
            ]
}

上代码

//判断是否需要提示更新App
- (void)shareAppVersionAlert {
   if(![self judgeNeedVersionUpdate])  return ;
    //App内info.plist文件里面版本号
    NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
    NSString *appVersion = infoDict[@"CFBundleShortVersionString"];
    NSString *bundleId   = infoDict[@"CFBundleIdentifier"];
    NSString *urlString = [NSString stringWithFormat:@"https://itunes.apple.com/cn/lookup?bundleid=%@", bundleId];
    //两种请求appStore最新版本app信息 通过bundleId与appleId判断
    //[NSString stringWithFormat:@"https://itunes.apple.com/cn/lookup?bundleid=%@", bundleId]
    //[NSString stringWithFormat:@"https://itunes.apple.com/cn/lookup?id=%@", appleid]
    NSURL *urlStr = [NSURL URLWithString:urlString];
 //创建请求体
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:urlStr];
    [NSURLConnection sendAsynchronousRequest:urlRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        if (connectionError) {
            //            NSLog(@"connectionError->%@", connectionError.localizedDescription);
            return ;
        }
        NSError *error;
        NSDictionary *resultsDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
        if (error) {
            //            NSLog(@"error->%@", error.localizedDescription);
            return;
        }
        NSArray *sourceArray = resultsDict[@"results"];
        if (sourceArray.count >= 1) {
            //AppStore内最新App的版本号
            NSDictionary *sourceDict = sourceArray[0];
            NSString *newVersion = sourceDict[@"version"];
            if ([self judgeNewVersion:newVersion withOldVersion:appVersion])
            {
                UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"提示:\n您的App不是最新版本,请问是否更新" message:@"" preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"暂不更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    //                    [alertVc dismissViewControllerAnimated:YES completion:nil];
                }];
                [alertVc addAction:action1];
                UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"去更新" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
                    //跳转到AppStore,该App下载界面
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:sourceDict[@"trackViewUrl"]]];
                }];
                [alertVc addAction:action2];
                [[UIApplication sharedApplication].delegate.window.rootViewController presentViewController:alertVc animated:YES completion:nil];
            }
        }
    }];
}
 //每天进行一次版本判断
- (BOOL)judgeNeedVersionUpdate {
       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 NO;
        }
        [[NSUserDefaults standardUserDefaults] setObject:dateString forKey:@"currentDate"];
        return YES;
}
//判断当前app版本和AppStore最新app版本大小
- (BOOL)judgeNewVersion:(NSString *)newVersion withOldVersion:(NSString *)oldVersion {
    NSArray *newArray = [newVersion componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"."]];
    NSArray *oldArray = [oldVersion componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"."]];
    for (NSInteger i = 0; i < newArray.count; i ++) {
        if ([newArray[i] integerValue] > [oldArray[i] integerValue]) {
            return YES;
        } else if ([newArray[i] integerValue] < [oldArray[i] integerValue]) {
            return NO;
        } els { }
    }
    return NO;
}

相关文章

  • 上架APP进行版本升级检测

    文章来源:iOS-App版本更新提示AppDelegate.m文件: 提示更新的界面增加:

  • iOS-App版本更新提示

    下面两个接口都可以获取相同的数据,就是App的各种信息 下面为接口中获取App的各种信息,对应的值仅为个人对比猜测...

  • 无标题文章

    //提示版本更新 [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. 方式...

网友评论

  • 砂缚柩:你确定[self judgeNeedVersionUpdate]; 里面的return 能跳出 shareAppVersionAlert函数、?
    BestVast:@你衣襟上的花 多谢指正,已经修改了。https://itunes.apple.com/cn/lookup?bundleId=com.xiaheng.BswkTest我这边使用bundleId是能获取到信息的
    fea854d2ddcc:我这边是只能用appleid获取的线上最新版本的信息 ,用bundleID获取不到,还有就是sourceArray.count > 1这个不行 要>=1才行,我用applied 总共也才获取到一个数据
    BestVast:@砂缚柩 多谢提醒,我看一下
  • BadRomance丶:现在 这样的提示 ,会被 下架 不,或者 审核 会 被通过吗
  • Daimer:你这个方法 写到哪里 是每个页面还是 主页 还是 AppDelegate 里面
    Daimer:@风_雨 看你具体有什么需求
    BestVast:@代码猿 这个方法只放在主页面使用一次就行吧

本文标题:iOS-App版本更新提示

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