2
我嘗試每週一重複本地通知。我發現localNotification.repeatInterval = kCFCalendarUnitWeekOfYear;
,但我不確定它是否有效。我如何在將來顯示所有本地通知時間?每週一重複本地通知
[[UIApplication sharedApplication] cancelAllLocalNotifications];
NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
[gregorian setLocale:[NSLocale currentLocale]];
NSDateComponents *nowComponents = [gregorian components:NSCalendarUnitYear | NSCalendarUnitWeekOfYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond fromDate:today];
[nowComponents setHour:18];
[nowComponents setMinute:05];
[nowComponents setSecond:00];
[nowComponents setWeekday:2];
NSDate * notificationDate = [gregorian dateFromComponents:nowComponents];
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
//localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
localNotification.fireDate = notificationDate;
localNotification.repeatInterval = kCFCalendarUnitWeekOfYear;
localNotification.soundName = @"localNotification_Sound.mp3";
localNotification.alertBody = @"Message?";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
我在上面的代碼中看到註釋掉的'fireData'行。爲什麼不嘗試設置一個本地通知,每隔30分鐘觸發一次,看看它是否可行? –
其實是一個好主意。我會嘗試。謝謝 – hantoren
我發現,localNotification.repeatInterval = NSCalendarUnitMinute;將每分鐘重複一次該代碼。但是我想每個星期一都有一個通知,所以我必須改變代碼中的內容嗎?我不確定是否必須使用localNotification.repeatInterval = NSCalendarUnitWeekOfYear/NSCalendarUnitWeekday或kCFCalendarUnitWeekOfYear ... – hantoren