日付の到来をユーザに警告するアプリを書いた。私は私が私のviewDidLoad
方法でこのコードを使用して入力された日付を実施し、保存した日付ピッカーがありますiOS:通知センターでアラートを発行する
- (void)viewDidLoad {
NSDate *storedDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"DatePickerViewController.selectedDate"];
[self.datePicker setDate:storedDate animated:NO];
}
をそして、これはデータを保存する方法である:
- (IBAction)dateChanged:(id)sender {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDate *selectedDate = [self.datePicker date];
[defaults setObject:selectedDate forKey:@"DatePickerViewController.selectedDate"];}
私がしようとしています
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"mm'/'dd'/'yyyy"];
NSDate *eventDate=[dateFormatter dateFromString:datePicker];
localNotif.fireDate = [eventDate dateByAddingTimeInterval:-13*60*60];
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = @"Event tomorrow!";
localNotif.alertAction = nil;
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication]presentLocalNotificationNow:localNotif];
return YES;
}
:周りの36時間にこのコードを使用した日付より前に通知センターでアラートを持っています私の問題はdateFromString:datePicker
です。私は何をそこに置くべきかわからない、私はピッカーではなく、テキストフィールドでこれを行うのに慣れている。どんな助けでも大歓迎です、ありがとう!
通知関連の質問を新しい質問に分割する必要があります。通常、このサイトの投稿ごとに1つの質問が必要です。 – esqew
、ありがとう! – John