3
我試圖在每個星期六重複UILocalNotification,但是我沒有成功。 我嘗試以下方法:每週六12:00點的UILocalNotification
// Create notification for every saturday at 12:00 am
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [gregorian components:NSUIntegerMax fromDate:[NSDate date]];
[components setWeekday:7]; // Saturday
[components setHour:12]; // 12 am
[components setMinute:0];
[components setSecond:0];
NSDate *fireDate = [gregorian dateFromComponents:components];
NSLog(@"%@", fireDate);
[[NotificationsManager sharedManager] configureLocalAlertMessage:message
fireDate:fireDate
repeatIntervalUnit:NSWeekCalendarUnit
type:kNotificationTypeMoneyBox];
但 「fireDate」 的回報: 「2013年3月12日11:00:00 +0000」,即今天。
任何幫助? 謝謝!
編輯:
代碼來配置通知
- (void)configureLocalAlertMessage:(NSString *)message fireDate:(NSDate *)date repeatIntervalUnit:(NSCalendarUnit)repeat type:(NotificationType)type {
// Local notification
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.timeZone = [NSTimeZone systemTimeZone];
notification.fireDate = date;
notification.repeatInterval = repeat;
notification.soundName = UILocalNotificationDefaultSoundName;
notification.hasAction = YES;
notification.alertBody = message;
notification.userInfo = @{kNotificationTypeKey : @(type)};
notification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
// Schedule
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
其中是您設置本地通知的代碼。此代碼僅用於創建日期。 – John 2013-03-12 15:42:25
我添加了新的信息。謝謝! 「 – mhergon 2013-03-12 15:49:19
」當信息不一致時,日曆可能會忽略某些組件參數,或者該方法可能會返回nil。「 – 2013-03-12 15:54:49