在一周中的某些日子重复 UILocalNotification

发布于 2024-11-05 15:07:01 字数 122 浏览 5 评论 0原文

我想将 UILocalNotification 的重复间隔自定义为一周中的某些天。我还没有找到任何关于这方面的信息。

如何设置一周中某些日子的通知重复间隔,例如在周日、周一和周五重复通知?

I want to customize the repeat interval of a UILocalNotification to be on certain days of the week. I haven't found any information about this.

How can I program the repeat interval for notifications for certain days of the week, for example, repeat a notification on Sunday, Monday, and Friday?

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

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

发布评论

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

评论(2

笨死的猪 2024-11-12 15:07:01

不幸的是,您无法将 UILocalNotificationrepeatInterval 属性设置为仅在特定日期重复。您可以设置每天重复、每月重复或每小时重复。因此,针对您的问题唯一可行的解​​决方案是,如果您想在周日、周一和周二设置闹钟,那么您必须设置 3 个闹钟(周日、周一和周二各一个),而不是一个闹钟。

Unfortunately you cannot set the repeatInterval property of UILocalNotification to repeat only on particular days. You can set either repeat daily (every day), monthly (every month) or hourly (every hour). So the only feasible solution for your question is that if you want to set an alarm on Sunday, Monday and Tuesday then you have to set 3 alarms (one each for Sunday ,Monday and Tuesday) rather than one alarm.

空宴 2024-11-12 15:07:01

如果您需要自定义 repeatInterval 属性。您必须在指定时间设置每个UILocalNotification。这是我的代码。


    void (^insertAlarm)(NSDate*fire,NSString*sound,int alarmCount) = ^(NSDate*fire,NSString*sound,int alarmCount){
        UILocalNotification* notification = [[UILocalNotification alloc] init];
        notification.timeZone = [NSTimeZone defaultTimeZone];
        notification.soundName = sound;
        notification.fireDate = fire;
        notification.repeatInterval = 0;
        notification.alertLaunchImage = IMG;
        notification.alertAction = ACTION_MSG;        
        notification.alertBody = BODY;
        notification.applicationIconBadgeNumber = 1;
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];
        [notification release];
    };

    insertAlarm(date,sound.fileName,0);
    insertAlarm([date dateByAddingTimeInterval:60],sound.fileName,1);

If you need to custom repeatInterval property. You have to setup each UILocalNotification on specify time. here is my codes.


    void (^insertAlarm)(NSDate*fire,NSString*sound,int alarmCount) = ^(NSDate*fire,NSString*sound,int alarmCount){
        UILocalNotification* notification = [[UILocalNotification alloc] init];
        notification.timeZone = [NSTimeZone defaultTimeZone];
        notification.soundName = sound;
        notification.fireDate = fire;
        notification.repeatInterval = 0;
        notification.alertLaunchImage = IMG;
        notification.alertAction = ACTION_MSG;        
        notification.alertBody = BODY;
        notification.applicationIconBadgeNumber = 1;
        [[UIApplication sharedApplication] scheduleLocalNotification:notification];
        [notification release];
    };

    insertAlarm(date,sound.fileName,0);
    insertAlarm([date dateByAddingTimeInterval:60],sound.fileName,1);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文