NSUserDefaults behaviour with app update

前端 未结 2 1032
被撕碎了的回忆
被撕碎了的回忆 2021-01-21 22:00

I have a method in my iOS app that updates the application when detects when my server has a greater version for my app (a new ipa version). If the user wants to download it, th

相关标签:
2条回答
  • 2021-01-21 22:47

    They will not be removed. And will have old values.

    if "HasLaunchedOnce" is used in the old version. use a new one and call it "HasUpdateLaunchedOnce".

    Check both values and decide what do you want to do.

    if (HasLaunchedOnce exists && HasUpdateLaunchedOnce not exists)
      // proceed
    
    0 讨论(0)
  • 2021-01-21 22:51

    You could use an integer stored in NSUserDefaults with a version number hard-coded for each version of the app. If the integer is lower than the hard-coded version, prompt for updates:

    NSInteger currentVersion = 3; // increment with each new version
    
    if ([[NSUSerDefaults standardUserDefaults] integerForKey:@"HasLaunchedForVersion"] < currentVersion) {
    
        [[NSUserDefaults standardUserDefaults] setInteger:currentVersion forKey:@"HasLaunchedForVersion"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        // This is the first launch for this version
    
    } else {
        // App hasn't been updated since last launch
    }
    
    0 讨论(0)
提交回复
热议问题