I have seen several answers here to how to detect a first run of a “standalone” app. But moving into a shared (iCloud) environment, is there a way to detect that an app has:
-
not ever been run anywhere
-
been run on this device
-
been run on another device
This a CoreData related question. If the app were document based – I could check for the presence of the document..
I’m using this code at present to load some items into an entity – the first time only. Subsequently, at present, a user can edit those items. However, next time the app is run on a new device, any changes will be lost.
NSString *bundleVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
appFirstStartOfVersionKey = [NSString stringWithFormat:@"first_start_%@", bundleVersion];
NSNumber *alreadyStartedOnVersion = [[NSUserDefaults standardUserDefaults] objectForKey:appFirstStartOfVersionKey];
if(!alreadyStartedOnVersion || [alreadyStartedOnVersion boolValue] == NO) {
[self firstStartCode];
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:YES] forKey:appFirstStartOfVersionKey];
}
and
-(void) firstStartCode {
NSLog(@"First Time building categories");
Category *category = (Category *)[NSEntityDescription insertNewObjectForEntityForName:@"Category" inManagedObjectContext:self.coreDataController.mainThreadContext];
category.name = @"Web Sites";
category = (Category *)[NSEntityDescription insertNewObjectForEntityForName:@"Category" inManagedObjectContext:self.coreDataController.mainThreadContext];
category.name = @"E-mail";
category = (Category *)[NSEntityDescription insertNewObjectForEntityForName:@"Category" inManagedObjectContext:self.coreDataController.mainThreadContext];
category.name = @"Social Networks";
You can check for the presence of the document in iCloud. The only problem is that iCloud asynchronously does what it wants, so there’s no guarantee as to what point you’ll actually be able to see that document.