How do I know if an iOS app has been recently installed or updated?

I have an application currently in the app store, which I am going to send an update in the near future.

With this update, I want to add code that the application will tell when it first starts application:didFinishLaunchingWithOptions , is this:

  • New installation from the app store.
  • Updated from previous version.

The application currently has no code to process in the application store.
The application uses the SQLite database, but for reasons that I will not enter, I do not want to use validation for its existence as a solution to this problem.

As a side question, without saving the data manually, is there an SDK that I can use to query when the application was installed on the device? (Preferably compatible with iOS 3.0)

I saw a similar question, but none of the answers apply to working with existing app store code.

+8
ios objective-c migration
source share
5 answers

You can save the version number to NSUserDefaults and update it accordingly.

If this does not work, you can release the intermediate version, which introduces a version control scheme.

If this is not an option, you can check for traces of previous launches from generated files or preferences that you set conditionally or lazily.

+7
source share

The following code may help answer your question about when the application was installed. I'm not sure if the application’s creation date is the Xcode build date or the download date, as this is not verified in the app store.

 NSString *bundleRoot = [[NSBundle mainBundle] bundlePath]; // eg /var/mobile/Applications/<GUID>/<AppName>.app NSFileManager *manager = [NSFileManager defaultManager]; NSDictionary* attrs = [manager attributesOfItemAtPath:bundleRoot error:nil]; NSLog(@"Build or download Date/Time of first version to be installed: %@", [attrs fileCreationDate]); NSLog(@"Date/Time of last install (unless bundle changed by code): %@", [attrs fileModificationDate]); NSString *rootPath = [bundleRoot substringToIndex:[bundleRoot rangeOfString:@"/" options:NSBackwardsSearch].location]; // eg /var/mobile/Applications/<GUID> attrs = [manager attributesOfItemAtPath:rootPath error:nil]; NSLog(@"Date/Time first installed (or first reinstalled after deletion): %@", [attrs fileCreationDate]); 
+18
source share

try this code, I know it's too late for this answer, but for the knwoldge exchange I go here.

  -(void) checkIsAppUpdated { NSString *urlString = @"http://itunes.apple.com/lookup?id=995558215"; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]]; [request setHTTPMethod:@"GET"]; NSError *error = nil; NSURLResponse *response = nil; NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; //NSString *stringReply = (NSString *)[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; if (error) { // NSLog(@"Error: %@", stringReply); //error reviced } else { //The response is in data //NSLog(@"Success: %@", stringReply); NSDictionary *dictResponse = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; float appStoreVersion=[[[[dictResponse objectForKey:@"results"] firstObject] objectForKey:@"version"] floatValue]; NSLog(@"app stroe version=%f",appStoreVersion); NSString *strLocalVersion=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; float localAppVersion=[strLocalVersion floatValue]; if (localAppVersion!=appStoreVersion) { //open app store url // NSString *iTunesLink = @"itms://itunes.apple.com/us/app/apple-store/id375380948?mt=8"; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/app/washthenfold/id995558215?mt=8"]]; } } } 

note

id: -replace id with your own app id. you can get the app id from itune connect selected app-> more info-> meta data p>

since the simulator does not have an app for the app, this code will not work on the simulator.

+3
source share

GBVersionTracking is a good tool for tracking the entire version history.

 [GBVersionTracking isFirstLaunchEver]; 
0
source share

Here is a simple code to find out if the current version is different (this code also works on the simulator.)

 -(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; } 

Note. Make sure that when you enter the new version in iTunes, this matches the version in the application that you are releasing. If not, the above code will always return YES regardless of whether the user is being updated.

0
source share

All Articles