I have an app that I want to make an update for it.
I have a list of items in application, but now I want to add versions for this items, so when item will be updated it will be marked as Updated. or if i will add a new item it will be marked like New.
But now for new users that install app first time all items should be new, and for users that already have app on their devices all items should be without any mark intially. I don't have any user defaults now in app so i can't check some value.
How can I check if app was already installed on device?
The answer is that you cannot know it if you didn't store any information that would help you to check if the user is updating the app or installing it from scratch.
You can use this code to know it, starting from the version you would implement it in.
BOOL versionUpgraded;
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
NSString *previousVersion = [prefs stringForKey:@"appVersion"];
if ([[NSUserDefaults standardUserDefaults] stringForKey:@"appVersion"] != nil)
{
// See if version is the same as the previous one. If NOT, it is an Update.
versionUpgraded = !([previousVersion isEqualToString: version]);
}
// No "appVersion" means new install.
else
{
versionUpgraded = YES;
}
if (versionUpgraded)
{
[[NSUserDefaults standardUserDefaults] setObject:version
forKey:@"appVersion"];
[[NSUserDefaults standardUserDefaults] setObject:previousVersion
forKey:@"prevAppVersion"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
What you can also do is to check if there is any data you cache, store etc. Anything in NSUserDefaults
, or any kind of database, or Documents
folder, that would mean that the app was already installed.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments