Time Out Your Beta App X Days From When it was Built

I’m working on an application that will be going into a private beta pretty soon, followed by a public beta. One of the things I wanted to do was make sure the application stopped working after 30 days from when it was built. This is to make sure the beta testers are running the latest and greatest version.

So to avoid having to manually update the date every time I release a new beta, I used gcc’s __DATE__ to come up with the following code:


NSDate expirationDate = [[NSDate dateWithNaturalLanguageString: [NSString stringWithCString:DATE]] addTimeInterval:(60602430/30 days/)];

if( [expirationDate earlierDate:[NSDate date]] 
     == expirationDate )
{
    int result = NSRunAlertPanel(@"Beta Expired", 
                 @"This beta has expired, please visit "
                 "http://roobasoft.com/rooAppNumber2 to grab"
                 "the latest version.", 
                 @"Take Me There", @"Exit", nil);

    if( result == NSAlertDefaultReturn )
    {
        [[NSWorkspace sharedWorkspace] openURL:
                  [NSURL URLWithString:
                   @"http://roobasoft.com/rooAppNumber2"]];
    }
    [[NSApplication sharedApplication] terminate:self];
}

Make sure the file that contains this code is always compiled before you ship your beta. Otherwise the DATE referenced will be whenever the file containing it was compiled. This works for me because I keep a separate “production” sandbox where a clean build is run before handing anything out.

Want to get fancy? Use Hyper Alert to make the URL clickable or to pretty it up a bit. You could probably have it pull release notes for the current release from a pre-defined location (that’s an assumption – I haven’ tried this).

SetADateForAnAppToExpire on CocoaDev wiki has some more information. Enjoy!.

p.s. If for some reason you’re interested in participating in a private beta of “rooAppNumber2” without knowing anything about it, send a note to rooAppNumber2@roobasoft.com I’ll make sure you get notified on how to participate when it’s ready. rooAppNumber2 will require OS X 10.4.

Leave a Reply


© 2006-2009 roobasoft, LLC