在该方法的起始插入以下代码:
-(void)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
dispatch_async(dispatch_queue_create("APP_EXPIRE_KILL", 0), ^{
// 检查程序是否过期
NSTimeInterval now = [[NSDate date] timeIntervalSince1970];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMM d yyyy"];
[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
NSDate *expiresDate = [formatter dateFromString:[NSString stringWithFormat:@"%s", __DATE__]];
// 一周过期
if (now - [expiresDate timeIntervalSince1970] >= 7*24*3600) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"您使用的程序是测试版本,目前已经过期,请更新到最新版本"
message:nil
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:NO];
sleep(10);
kill(getpid(), 9);
}
});