#ios #objective_c #xcode #notifications
Имеется будильник. Не могу сделать, чтобы при срабатывании будильника приходило уведомление.
Нужно сделать push уведомление со звуком, пользователь должен ее отключать.
Сейчас сделал просто notification уведомление.
Можно ли как-то сделать, используя notification то, о чем я написал выше?
UILocalNotification * notification = [[UILocalNotification alloc] init];
notification.userInfo = dict;
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.fireDate = self.eventDate;
notification.alertBody = _luck;
notification.applicationIconBadgeNumber = 1;
notification.soundName = UILocalNotificationDefaultSoundName;
notification.repeatInterval = 0;
[[UIApplication sharedApplication]scheduleLocalNotification:notification];
[[NSNotificationCenter defaultCenter] postNotificationName:@"NewEvent" object:nil];
[self.navigationController popViewControllerAnimated:YES];
Ответы
Ответ 1
В iOS8 и позже, ваше приложение должно запросить у пользователя разрешение на отправку уведомлений (даже локальных). Чтобы это сделать выполните следующий код до того, как вы делаете scheduleLocalNotification: UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert; UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
Комментариев нет:
Отправить комментарий