Я пытаюсь заставить мои удаленные уведомления работать должным образом, но я столкнулся с некоторыми проблемами.
Я отправляю уведомления со своего сервера с флагом content-available
, установленным на 1
, так что мой didReceiveRemoteNotification
запускается, и я отображаю уведомление пользователю, вызывая следующий метод внутри didReceiveRemoteNotification
:
- (void) showPush:(NSString *)message
{
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.body = message;
content.sound = [UNNotificationSound defaultSound];
NSString *identifier = @"UYLLocalNotification";
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier
content:content trigger:nil];
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
if (error != nil) {
NSLog(@"Something went wrong: %@",error);
}
}];
}
Уведомления, отправляемые, когда приложение находится в приостановленном состоянии, вообще не отображаются, а отображаются после того, как приложение было открыто, а затем снова закрыто, например:
-> App is suspended: notification is sent
-> App is opened and in the foreground: I can see that the notification has been processed
-> App is closed and in the background: notification is being displayed with a banner
Буду признателен за любые предположения, почему это не работает должным образом.