I\'m planning on opening up an in app store and I\'d like to give existing users some of the items for free.
I thought of releasing an update which would store some
Answering to see if people can find fault in this. It seemed longer than the others I find here, but it does tell you if app is running for the first time since updating (for this you have to change your info.plist)...
// called during startup, compares the current version string with the one stored on standardUserDefaults
+ (BOOL)isFreshInstallOrUpdate
{
BOOL ret = YES;
NSString *cfBundleVersionStored = [[NSUserDefaults standardUserDefaults] objectForKey:@"CFBundleVersion"];
NSString *cfBundleShortVersionStringStored = [[NSUserDefaults standardUserDefaults] objectForKey:@"CFBundleShortVersionString"];
NSString *cfBundleVersionPlist = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];;
NSString *cfBundleShortVersionStringPlist = [[NSBundle mainBundle] objectForInfoDictionaryKey:
@"CFBundleShortVersionString"];
ret = [cfBundleVersionPlist compare:cfBundleVersionStored] != NSOrderedSame ||
[cfBundleShortVersionStringPlist compare:cfBundleShortVersionStringStored] != NSOrderedSame;
return ret;
}
// calling this once will necessarily cause isFreshInstall to return false
+ (void)setStoredVersionNumber
{
NSString *cfBundleVersionPlist = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
NSString *cfBundleShortVersionStringPlist = [[NSBundle mainBundle] objectForInfoDictionaryKey:
@"CFBundleShortVersionString"];
[[NSUserDefaults standardUserDefaults] setObject:cfBundleVersionPlist forKey:@"CFBundleVersion"];
[[NSUserDefaults standardUserDefaults] setObject:cfBundleShortVersionStringPlist forKey:@"CFBundleShortVersionString"];
// setting now as unfresh!
[[NSUserDefaults standardUserDefaults] synchronize];
}