我的应用检查应用商店中是否有可用的更新。我在 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:
最佳答案
我能够解决我的问题。感谢@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/