Repeat UILocalNotification on certain days of week

2019-02-18 19:54发布

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?

2条回答
smile是对你的礼貌
2楼-- · 2019-02-18 20:24

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);
查看更多
闹够了就滚
3楼-- · 2019-02-18 20:35

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.

查看更多
登录 后发表回答