检查我的应用在 AppStore 上是否有新版本 [英] Check if my app has a new version on AppStore

查看:74
本文介绍了检查我的应用在 AppStore 上是否有新版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户使用时手动检查我的应用程序是否有新更新,并提示他下载新版本.我可以通过在应用商店中检查我的应用版本来做到这一点吗 - 以编程方式?

I would like to manually check if there are new updates for my app while the user is in it, and prompt him to download the new version. Can I do this by checking the version of my app in the app store - programatically?

推荐答案

这是一个简单的代码片段,可以让您知道当前版本是否不同

Here is a simple code snippet that lets you know if the current version is different

-(BOOL) needsUpdate{
    NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString* appID = infoDictionary[@"CFBundleIdentifier"];
    NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?bundleId=%@", appID]];
    NSData* data = [NSData dataWithContentsOfURL:url];
    NSDictionary* lookup = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

    if ([lookup[@"resultCount"] integerValue] == 1){
        NSString* appStoreVersion = lookup[@"results"][0][@"version"];
        NSString* currentVersion = infoDictionary[@"CFBundleShortVersionString"];
        if (![appStoreVersion isEqualToString:currentVersion]){
            NSLog(@"Need to update [%@ != %@]", appStoreVersion, currentVersion);
            return YES;
        }
    }
    return NO;
}

注意:确保当您在 iTunes 中输入新版本时,该版本与您正在发布的应用程序中的版本相匹配.如果不是,那么无论用户是否更新,上述代码都将始终返回 YES.

Note: Make sure that when you enter the new version in iTunes, this matches the version in the app you are releasing. If not then the above code will always return YES regardless if the user updates.

这篇关于检查我的应用在 AppStore 上是否有新版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆