如何在特定日期设置警报并每周重复安排

时间:2011-04-17 11:31:06

标签: iphone objective-c alarm uilocalnotification

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
   return;

localNotif.fireDate = selected;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.repeatCalendar = [NSCalendar currentCalendar];

if (isSun) {
    [components setWeekday:1];
    [localNotif setRepeatInterval:(NSInteger)components];
}

if (isMon) {
    [components setWeekday:2];
    [localNotif setRepeatInterval:(NSInteger)components];   
}

if (isTue) {
    [components setWeekday:3];
    [localNotif setRepeatInterval:(NSInteger)components];
}

if (isWed) {
    [components setWeekday:4];
    [localNotif setRepeatInterval:NSWeekCalendarUnit];
}

if (isThu) {
    [components setWeekday:5];
    [localNotif setRepeatInterval:(NSInteger)components];
}

if (isFri) {
    [components setWeekday:6];
    [localNotif setRepeatInterval:(NSInteger)components];
}

if (isSat) {
    [components setWeekday:7];
    [localNotif setRepeatInterval:(NSInteger)components];
}

我想在所选日期设置闹钟,请更正我的代码我是iphone的新手。 帮助我。

1 个答案:

答案 0 :(得分:2)

请参阅Apple iOS Developer Library中的此示例:

Scheduling, Registering, and Handling Notifications