美文网首页
ios 过期检测

ios 过期检测

作者: 来宝 | 来源:发表于2016-09-10 02:55 被阅读97次

    在该方法的起始插入以下代码:

    -(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);
        }
    });
    

    相关文章

      网友评论

          本文标题:ios 过期检测

          本文链接:https://www.haomeiwen.com/subject/rydyettx.html