ios - “可用更新”弹出窗口不显示

标签 ios objective-c iphone

我的应用检查应用商店中是否有可用的更新。我在 didFinishLaunchingWithOptions 方法中调用它。

(BOOL)checkIfNeedsUpdate {
    BOOL needsUpdate = NO;
    NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary];

    NSString* appID = infoDictionary[@"CFBundleIdentifier"];
    NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/ph/lookup?bundleId=%@", appID]];
    NSData* data = [NSData dataWithContentsOfURL:url];
    NSDictionary* lookup = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

    if([lookup[@"resultCount"] integerValue] == 1) {
        NSString* appStoreVersion = lookup[@"results"][0][@"version"];
        NSString* currentVersion = infoDictionary[@"CFBundleShortVersionString"];
        if(![appStoreVersion isEqualToString:currentVersion]) {
            [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"logined"];
            [[NSUserDefaults standardUserDefaults] synchronize];

            needsUpdate = YES;
        }
    }

    return needsUpdate;
}

因此,为了对此进行测试,我降级了我拥有的应用程序版本并在模拟器上运行它,这非常有效。但是,当我尝试在我的设备上运行应用程序时,“可用更新”弹出窗口没有显示,因此没有更新应用程序。知道我的代码有什么问题吗?如何显示“可用更新”弹出窗口以便能够更新。

任何帮助将不胜感激。 提前致谢。

这是 uialertview:

versions

最佳答案

我能够解决我的问题。感谢@rokjarc 的评论。 这是我的做法:

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

    if([lookup[@"resultCount"] integerValue] == 1) {
        NSString* appStoreVersion = lookup[@"results"][0][@"version"];
        NSString* currentVersion = infoDictionary[@"CFBundleShortVersionString"];
        if(![appStoreVersion isEqualToString:currentVersion]) {
            [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"logined"];
            [[NSUserDefaults standardUserDefaults] synchronize];
            [[Harpy sharedInstance] checkVersion];
        }
    }
}

我用了Harpy - 第三方库通知用户应用程序商店中的应用程序有更新。 感谢花一分钟时间阅读我的询问的人。

关于ios - “可用更新”弹出窗口不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32473882/

相关文章:

iphone - 自己的健康指标出现问题。 Cocos2d

iOS 表格 View 。自定义单元格始终具有 320 宽度和 44 高度的内容 View

iphone - 如何加载顶部有关闭按钮的 UIWebView?

iphone - 如何在 iOS 上使用 Facebook API Graph 增加签到地点的数量

iphone - iPhone 的翻译?

ios - 解析查询在只有一个对象时发现两个对象

ios - 将应用程序从 iOS 5.1 更新到 6.0 - 新警告?

ios - 如何最有效的学习IOS开发?

ios - 哪个控件用于其中一个或值?

objective-c - 从 NSData 到 NSImage 的转换