I'm trying trigger local notification when I receive remote push notification (VoIP PushKit) which start my app in the background.
I see my local notification in array of the pending notifications at the UNUserNotificationCenter.
[[UNUserNotificationCenter currentNotificationCenter] getPendingNotificationRequestsWithCompletionHandler:
^(NSArray<UNNotificationRequest *> * _Nonnull requests)
{
NSLog(@"Local notifications: %@",requests);
}];
"<UNNotificationRequest: 0x17162e500; identifier: 2A364020-3BA2-481B-9255-16EBBF2F4484, content: <UNNotificationContent: 0x1708e8080; title:test, subtitle: (null), body: test2, categoryIdentifier: missed, launchImageName: , peopleIdentifiers: (\n), threadIdentifier: , attachments: (\n), badge: 1, sound: <UNNotificationSound: 0x1704bfe60>, hasDefaultAction: YES, shouldAddToNotificationsList: YES, shouldAlwaysAlertWhileAppIsForeground: YES, shouldLockDevice: YES, shouldPauseMedia: NO, isSnoozeable: NO, fromSnooze: NO, darwinNotificationName: (null), darwinSnoozedNotificationName: (null), trigger: <UNTimeIntervalNotificationTrigger: 0x171624260; repeats: NO, timeInterval: 5.000000>>"
But it doesn't appear after 5 sec. I use UNTimeIntervalNotificationTrigger.
I have successfully call the local notification when the application in the foreground. I use the same function for trigger by calling it by pressing the button.
Is there any way to trigger local notification when iOS app is in the background?
Yes its possible, and if its not working for you then you must be doing something incorrect with your code, but you didn't show it so can't comment on that.
Here's some working debugging code I have to display a notification on voip push receiving: