使用 NSTimeInterval 的应用程序过期

发布于 2024-08-16 01:09:50 字数 403 浏览 2 评论 0原文

我如何设置此方法以在应用程序首次启动后 30 天显示警报面板?

-(void)awakeFromNib

{

    NSDate * today = [NSDate date];

    NSTimeInterval expiry = ();


    if ([today timeIntervalSinceReferenceDate] > expiry){
        NSRunAlertPanel(@"Trial period has ended", @"Please Register", nil, nil, nil);
        NSLog(@"expired");
        [[NSApplication sharedApplication] terminate:self];
    }

}

How would I set this method to display the alert panel 30 days from the initial launch of the application?

-(void)awakeFromNib

{

    NSDate * today = [NSDate date];

    NSTimeInterval expiry = ();


    if ([today timeIntervalSinceReferenceDate] > expiry){
        NSRunAlertPanel(@"Trial period has ended", @"Please Register", nil, nil, nil);
        NSLog(@"expired");
        [[NSApplication sharedApplication] terminate:self];
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

祁梦 2024-08-23 01:09:50

使用 上的 day 属性NSDateComponents 用于计算距离当前日期一定数量的日期:

NSDate *today = [NSDate date];

NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
dateComponents.day = 30; // 30 days from launch

NSDate *expDate = [[NSCalendar currentCalendar] dateByAddingComponents:dateComponents toDate:today options:0];

此检查仅应在应用程序第一次打开时进行。 expDate 应保留。每次应用程序在第一次后重新启动时,请与第一次日期进行日期比较。

// compare the dates
if ([today compare:expDate] == NSOrderedDescending) {
    // trial expired
}

Use the day property on NSDateComponents to calculate a date a certain number of dates from the current date:

NSDate *today = [NSDate date];

NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
dateComponents.day = 30; // 30 days from launch

NSDate *expDate = [[NSCalendar currentCalendar] dateByAddingComponents:dateComponents toDate:today options:0];

This check should only be done the first time the app opens. expDate should be persisted. Every time the app launches fresh after the first time, do a date comparison from that first date.

// compare the dates
if ([today compare:expDate] == NSOrderedDescending) {
    // trial expired
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文