問題は、通知が設定されている間に処理が進まないことです。ペン先に日付ピッカーとその下のボタンを置いています。ユーザーは、ピッカーに日付を設定し、ボタンをクリックすると、日付の60時間前に通知が設定されます。だから、私はちょうど日付ピッカーの日付を認識するために砲撃者を取得することに問題があるように見えます。ここでは、コードで、それは私のビューコントローラである:iOS:ローカル通知が時間通りに起動しない
- (IBAction)scheduleNotifButton:(id)sender {
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
NSDate *selectedDate = [self.datePicker date];
localNotif.fireDate = [selectedDate dateByAddingTimeInterval:-60*60*60];
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = @"Event is in three days!";
localNotif.alertAction = nil;
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Event scheduled."
message:@"You will be notified three days before the event."
delegate:nil
cancelButtonTitle:@"Okay."
otherButtonTitles:nil];
[alert show];
}
そしてここでは、いくつかの追加のコードは、それが助け場合、これはユーザーが入力しピッカーで日付を節約を扱う私のビューコントローラからより多くのコードです:
- (IBAction)dateChanged:(id)sender
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDate *selectedDate = [self.datePicker date];
[defaults setObject:selectedDate forKey:@"ImportantDatesViewController.selectedDate"];
[defaults synchronize];
}
- (void)viewDidLoad {
NSDate *storedDate = [[NSUserDefaults standardUserDefaults]
objectForKey:@"ImportantDatesViewController.selectedDate"];
if (storedDate == nil) {
storedDate = [NSDate date];
}
[self.datePicker setDate:storedDate animated:NO];
}
私は今、3日間、このコードを掘ってきたし、彼らがすることになっているとき、私の通知が通過していないしている理由を理解することはできません。どんな助けでも大歓迎です、ありがとう!
ありがとう。アラートは送信されますが、ユーザーがピッカーに入力した日付には依存していないようです。 – John