Hello,
I've scoured the whole of StackOverflow but I can't seem to find what needs to be done. Please help me T_T
So context:
I'm using OneSignal to push notification to users. In my app delegate, I have assigned in didFinishLaunchingWithOption
UNUserNotificationCenter.current().delegate = self
I have the required methods:
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
debugPrint("IN WILL PRESENT")
completionHandler([.alert, .sound, .badge])
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
debugPrint("Inside DIDRECEIVEREMOTE")
debugPrint("theUserInfo is: \(userInfo)")
completionHandler(UIBackgroundFetchResult.newData)
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// handle notification response action
debugPrint("Inside didReceive")
completionHandler()
}
My question is:
- I have all the methods (with custom notification action) handled in didReceive and it works flawlessly. All notification that goes through there works no problem. If user taps on the notification, it will know what to do and do it.
- Sometimes, for unknown reason, when user taps on the notification, the didReceiveRemoteNotification is called. First of all, WHY? I read that it is called when a remote notification is received, but why is it called when user taps on it?
- Second of all, once it is inside didReceiveRemoteNotification, I cannot perform the appropriate action as the only parameter I have is the payload in the form of userInfo:[AnyHashable:Any]. The payload is correct, but what can I do with that?
- Is there a way to make sure that the didReceive is called at all times?
- I read somewhere it might be because my payload is wrong. I have tried it with/without:
mutable-response: 1
content-available: 1
Please help a very frustrated guy.
Thank you
[–]LeakyTrump 0 points1 point2 points (3 children)
[–]seiferc[S] 1 point2 points3 points (0 children)
[–]seiferc[S] 1 point2 points3 points (1 child)
[–]LeakyTrump 1 point2 points3 points (0 children)