Kill App after Expire Date (Suicidal Code Redux)


/ Published in: Objective C
Save to your folder(s)

Using a gcc predefined macro, __DATE__, the code can know for itself when it was compiled, and build in an expiration date based on that value.

The former code (http://snipplr.com/view/3448/kill-app-after-expire-date/) was not internationalised and might cause an issue when run outside of English speaking countries. This code resolves the locale issue.


Copy this code and paste it in your HTML
  1. // Based on original code by Daniel Jakult, based on an idea from Brian Cooke.
  2. #ifdef BETA // 4 week expiration
  3. #define EXPIREAFTERDAYS 28
  4. #endif
  5.  
  6. #if EXPIREAFTERDAYS
  7. NSString* compileDateString = [NSString stringWithUTF8String:__DATE__];
  8. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  9. [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
  10. [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@”en_US”]
  11. autorelease]];
  12. [dateFormatter setDateFormat:@"MMM dd yyyy"];
  13. NSDate *compileDate = [dateFormatter dateFromString:compileDateString];
  14. [dateFormatter release];
  15. NSDate *expireDate = [compileDate addTimeInterval:(60*60*24* EXPIREAFTERDAYS)];
  16.  
  17. if ([expireDate earlierDate:[NSDate date]] == expireDate)
  18. {
  19. // Run an alert or whatever
  20.  
  21. // Quit!
  22. [NSApp terminate:self];
  23. }
  24. #endif

URL: http://www.daytimesoftware.com/blog/2007/10/suicidal-code-redux

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.