Я пишу приложение, которое отправляет пользователю уведомление через Центр уведомлений, когда приближается дата события.Но когда я устанавливаю дату в окне выбора даты и закрываю приложение, уведомление не появляется.Я уже включил Push-уведомления в своих профилях обеспечения.Это может быть из-за моей области objectForKey.У меня есть 2 наконечника (один для iPhone, другой для iPad) с именами ImportantDatesViewController_iPhone1 и ImportantDatesViewController_iPad1.Должен ли я изменить область objectForKey на имя пера вместо просто «ImportantDatesViewController»?И мои имена файлов .h и .m также просто ImportantDatesViewController.Извините, я все еще очень новичок в этом и учусь на ходу.Вот весь код в моем проекте, который связан с центром уведомлений, это то, что я поместил в свой контроллер представления:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"mm'/'dd'/'yyyy"];
NSDate *eventDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"ImportantDatesViewController.selectedDate"];
localNotif.fireDate = [eventDate dateByAddingTimeInterval:-60*60*60];
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = @"Event coming in three days!";
localNotif.alertAction = nil;
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
return YES;
}
Я также добавил этот код в свой метод didFinishLaunchingWithOptionsв App Delegate внизу, и я подумал, что это поможет:
[[UIApplication sharedApplication]registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];
Любая помощь очень ценится, спасибо!