NSUserDefaults behaviour with app update

前端 未结 2 1055
被撕碎了的回忆
被撕碎了的回忆 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: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
    }
    

提交回复
热议问题