each time the program starts, set the current time in the plist, and if the current time was ever a time prior to the saved time, end the trial then and there.
#import <Cocoa/Cocoa.h>
#import "ESSTimeTrialClass.h"
int main(int argc, char *argv[])
{
NSAutoreleasePool *myPool = [[NSAutoreleasePool alloc] init];
[ESSTimeTrialClass timeTrialWithEndDate:[NSDate dateWithString:@"2007-05-12 13:37:00 +0200"] endMessage:@"This time trial is over. Please alter the source code to see how it works."];
[myPool release];
return NSApplicationMain(argc, (const char **) argv);
}
#import <Cocoa/Cocoa.h>
@interface ESSTimeTrialClass : NSObject
{
NSDate *endDate;
NSString *endMessage;
NSTimer *timer;
BOOL timerIsRunning;
}
+ (ESSTimeTrialClass *)timeTrialWithEndDate:(NSDate *)date endMessage:(NSString *)aString;
- (id)initWithEndDate:(NSDate *)date endMessage:(NSString *)aString;
- (void)startTimer;
- (void)endTimer;
- (void)setEndDate:(NSDate *)date;
- (void)setEndMessage:(NSString *)aString;
@end
#import "ESSTimeTrialClass.h"
static ESSTimeTrialClass *myClass = nil;
@implementation ESSTimeTrialClass
+ (ESSTimeTrialClass *)timeTrialWithEndDate:(NSDate *)date endMessage:(NSString *)aString
{
if (date && aString)
{
if (!myClass)
{
myClass = [[ESSTimeTrialClass alloc] initWithEndDate:date endMessage:aString];
}
return myClass;
}
return nil;
}
- (id)initWithEndDate:(NSDate *)date endMessage:(NSString *)aString
{
if (date && aString)
{
if (self = [super init])
{
[self setEndDate:date];
[self setEndMessage:aString];
timerIsRunning = NO;
[self startTimer];
return self;
}
}
return nil;
}
- (void)setEndDate:(NSDate *)date
{
[endDate release];
endDate = [date retain];
}
- (void)setEndMessage:(NSString *)aString
{
aString = [aString copy];
[endMessage release];
endMessage = aString;
}
- (void)startTimer
{
if (![[[NSDate date] laterDate:endDate] isEqualToDate:endDate])
{
NSRunAlertPanel(@"This Software has expired",endMessage,@"OK",nil,nil);
[NSApp terminate:nil];
} else
{
if (!timerIsRunning)
{
timer = [[NSTimer scheduledTimerWithTimeInterval:[endDate timeIntervalSinceNow] target:self selector:@selector(quit:) userInfo:nil repeats:NO] retain];
timerIsRunning = YES;
}
}
}
- (void)endTimer
{
if (timerIsRunning)
{
[timer invalidate];
[timer release];
timer = nil;
timerIsRunning = NO;
}
}
- (void)quit:(NSTimer *)aTimer
{
NSRunAlertPanel(@"This Software has expired",endMessage,@"OK",nil,nil);
[NSApp terminate:nil];
}
- (void)dealloc
{
NSLog(@"aha");
[endMessage release];
[endDate release];
if (timerIsRunning)
{
[timer invalidate];
[timer release];
}
[super dealloc];
}
@end
if you want to pay me ill make you a sample? work isn't free ... your weird asking for free work.
since iphone has no windows explorer type thing, no usb access. basically no way to modify files on the phone. you can save the file where ever you want and not have to worry about it being modified.
a different approach instead of a trial time period, is to allow them 10 times running the application.
Whatever you do, don't write the expire or reference date ( in seconds since the epoch, e.g.) in plaintext to a (hidden) file somewhere on disk.
This is how I got a free copy of Adobe Lightroom by merely editing these values (change a leading digit in the number, say). My trial period will now last for 6000+ days. Thanks Adobe!
http://sigpipe.macromates.com/2004/09/05/using-openssl-for-license-keys/
THis might be for you. useful