毎週土曜日に 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-03-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];
}