Terminate the Mac OSX application for a certain period of time and ask the user to update

What is the recommended way to expire a Mac OSX beta application for a specific period of time (i.e. 14 days) and then ask the user to upgrade (in Cocoa)?

Am I just doing a date calculation every time a user launches an application? Also, is there a way to enable the update using the Sparkle infrastructure if it’s expired?

thanks

+4
source share
2 answers

If you are looking for a 14-day rolling beta - i.e. beta expires 14 days after the first launch of the application, I would recommend using userDefaults and checking it at startup.

Specifically, calling isBetaExpired from the code below in your DidFinishLaunching application:

- (void)setDateForKey:(NSString*)key date:(NSDate*)date { [[NSUserDefaults standardUserDefaults] setObject:date forKey:key]; } - (NSDate*)getDateForKey:(NSString*)key { return [[NSUserDefaults standardUserDefaults] objectForKey:key]; } - (BOOL)isBetaExpired { NSString* betaKey = @"v1.0BetaExpireDate"; double maxElapsed = 60 * 60 * 24 * 14; // 14 days NSDate* betaDate = [self getDateForKey:betaKey]; if (!betaDate) { // if we didn't have a beta start date already, set it to now betaDate = [NSDate date]; [self setDateForKey:betaKey date:betaDate]; } // determine how long it has been since the beta started double elapsed = [betaDate timeIntervalSinceNow]; // check if it is expired BOOL expired = (elapsed >= maxElapsed); return expired; } 
0
source

I think for a beta that will certainly expire on a given date, you can just copy that date. Then you can compare:

 NSDate* expirationDate = [NSDate dateWithString: @"2012-03-24 10:45:32 +0600"]; if ([expirationDate compare:[NSDate date]] == NSOrderedAscending) { //is expired -> present update recommendation } 

If you want to be flexible with a date, you can, for example, create a .txt file on your server that contains a date string. This can be easily downloaded:

 NSString* dateString = [NSString stringWithContentsOfURL:myURL encoding:NSUTF8StringEncoding error:NULL]; NSDate* expirationDate = [NSDate dateWithString: dateString]; 

Of course, it would be nice if you automatically submit a tip for a glitter update. You can turn off automatic update checking (see https://github.com/andymatuschak/Sparkle/wiki/make-preferences-ui ), and then when the beta testing time has expired, manually check for updates and / or activate automatic checking , (see: https://github.com/andymatuschak/Sparkle/wiki/customization )

+5
source

Source: https://habr.com/ru/post/1441025/


All Articles