Posted By

zingo on 08/03/07


Tagged

cocoa osx objc macro expire xcode gcc


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

tcol
joellevin
cgrainger
mattnews
nsbuckner
wpellis


kill app after expire date


 / Published in: Objective C
 

URL: http://www.red-sweater.com/blog/371/suicidal-code

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.

For a internationalised version see: http://snipplr.com/view/7196/kill-app-after-expire-date-suicidal-code-redux/

  1. // For a internationalised version
  2. // see: http://snipplr.com/view/7196/kill-app-after-expire-date-suicidal-code-redux/
  3.  
  4. // Two-week expiration
  5. #define EXPIREAFTERDAYS 14
  6.  
  7. #if EXPIREAFTERDAYS
  8. // Idea from Brian Cooke.
  9. NSString* nowString =
  10. [NSString stringWithUTF8String:__DATE__];
  11. NSCalendarDate* nowDate =
  12. [NSCalendarDate dateWithNaturalLanguageString:nowString];
  13. NSCalendarDate* expireDate =
  14. [nowDate addTimeInterval:(60*60*24* EXPIREAFTERDAYS)];
  15.  
  16. if ([expireDate earlierDate:[NSDate date]] == expireDate)
  17. {
  18. // Run an alert or whatever
  19.  
  20. // Quit!
  21. [NSApp terminate:self];
  22. }
  23. #endif

Report this snippet  

You need to login to post a comment.