簡體   English   中英

如何在Mac應用程序中每天重復執行NSUserNotification?

[英]How do I make NSUserNotification repeat daily in Mac application?

我想為我的Mac應用程序創建每日提醒。 我設置了deliveryRepeatInterval,但是沒有用。 僅創建1條通知。 我的代碼如下:

    NSDate *date = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [calendar components:(NSYearCalendarUnit|NSDayCalendarUnit|NSMonthCalendarUnit|NSHourCalendarUnit) fromDate:date];
    components.timeZone = [NSTimeZone localTimeZone];
    [components setDay: components.day + 1];
    [components setHour: 20];
    NSDate *dateToFire = [calendar dateFromComponents:components];

    NSUserNotification *localNotif = [NSUserNotification new];
    localNotif.deliveryRepeatInterval.day = 1;
    localNotif.informativeText = @"Hello";
    localNotif.deliveryTimeZone = [NSTimeZone localTimeZone];
    localNotif.deliveryDate = dateToFire;

    NSUserNotificationCenter *notiCenter = [NSUserNotificationCenter defaultUserNotificationCenter];
    [notiCenter scheduleNotification:localNotif];

我已經修復了代碼,並且可以正常工作。

NSDateComponents *repeatTime = [NSDateComponents new];
repeatTime.day = 1;
localNotif.deliveryRepeatInterval = repeatTime;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM