We Recommend

Programming in Objective-C Programming in Objective-C
Programming in Objective-C is a concise, carefully written tutorial on the basics of Objective-C and object-oriented programming. The book makes no assumption about prior experience with object-oriented programming languages or with the C language (upon which Objective-C is based). And because of this, both novice and experienced programmers alike can use this book to quickly and effectively learn the fundamentals of Objective-C.


Posted By

zingo on 08/03/07


Tagged

osx objc macro expire xcode gcc


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

tcol
joellevin


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.


  1. // Two-week expiration
  2. #define EXPIREAFTERDAYS 14
  3.  
  4. #if EXPIREAFTERDAYS
  5. // Idea from Brian Cooke.
  6. NSString* nowString =
  7. [NSString stringWithUTF8String:__DATE__];
  8. NSCalendarDate* nowDate =
  9. [NSCalendarDate dateWithNaturalLanguageString:nowString];
  10. NSCalendarDate* expireDate =
  11. [nowDate addTimeInterval:(60*60*24* EXPIREAFTERDAYS)];
  12.  
  13. if ([expireDate earlierDate:[NSDate date]] == expireDate)
  14. {
  15. // Run an alert or whatever
  16.  
  17. // Quit!
  18. [NSApp terminate:self];
  19. }
  20. #endif

Report this snippet 

You need to login to post a comment.