Reputation: 51
My app checks if there is update available in app store. I call this in didFinishLaunchingWithOptions method.
(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;
}
So to test this, I downgraded the app version that I have and run it on the simulator and this works like a charm. However, when I try running the app on my device the "Update Available" pop up is not displaying thus not updating the app. Any idea what is wrong with my code? How can I display the "Update Available" pop up to be able to update.
Any help will be very much appreciated. Thanks in advance.
Here's the the uialertview:
Upvotes: 1
Views: 399
Reputation: 51
I was able to solve my problem. Thanks to @rokjarc's comment. Here's how I did it:
(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];
}
}
}
I used Harpy - third party library to inform user's that there is an update for the app in app store. Thanks to the people who took a minute to read my inquiry.
Upvotes: 2