ESSTimeTrialClass
Language: Objective-C, Author: Matthias Gansrigler
License: Public domain
This class has one simple purpose: Terminate the application, once a certain date has been reached.
You just pass the class a date (the date the trial should end) and a termination message and the class does the rest.
If the date is before the current date, it will terminate immediately (showing a termination message), if it's some where in the future, it will start a timer and will then terminate the application.
ESSTimeTrialClass source preview
//
// ESSTimeTrialClass.m
// Cave Canem
//
// Created by Matthias Gansrigler on 5/12/07.
// Copyright 2007 Eternal Storms Software. All rights reserved.
//
#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
ESSTimeTrialClass header preview
//
// ESSTimeTrialClass.h
// Cave Canem
//
// Created by Matthias Gansrigler on 5/12/07.
// Copyright 2007 Eternal Storms Software. All rights reserved.
//
#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
Download Archive
Compatible with:
- Mac OS X 10.3
- Mac OS X 10.4 PPC
- Mac OS X 10.4 Intel
- Mac OS X 10.5 PPC
- Mac OS X 10.5 Intel

This doesn't seem to work at all. All i get is a blank NSWindow, but no alert although the exp. date is set to 2007.