Open JWiseCoder opened 3 years ago
I'm experiencing the same issue with an app that was recently updated to NS7 and the latest nativescript/firebase plugin 11.1.3.
Notifications work great in the background, but foreground crashes app immediately with the exception mentioned above.
Hey @JWiseCoder , you were correct that this had to do with the shared delegate plugin. @edusperoni just pushed a fix for this a few days ago and it resolved the issue for me! Thanks for such a quick fix on that Eduardo!
https://github.com/NativeScript/plugins/pull/83
I needed to specifically install and update to version 1.0.2 of @nativesript/shared-notification-delegate 👍
nativescript/firebase 11.1.3 nativescript 7.1.2 nativescript/core 7.1.3 nativescript/ios 7.1.0
I set up push notifications in my app using firebase/messaging. I set everything up and called registerForPushNotifications, and I got the token back for sending push notifications to the app. However, when I pushed a notification with the app in the foreground, the app crashes with an EXC_BAD_ACCESS exception. (If the app is in the background, the push notification goes through fine).
Digging through it, I found that the source of the problem was in the
userNotificationCenterWillPresentNotificationWithCompletionHandler
function of theFirebaseNotificationDelegateObserverImpl
class. The crash is occurring when thecompletionHandler
is called.Apparently, this callback comes from the @nativescript/shared-notification-delegate plugin. The
userNotificationCenterWillPresentNotificationWithCompletionHandler
function inside theUNUserNotificationCenterDelegateImpl
class receives the message as the notification delegate, and it creates its ownchildHandler
function that wraps thecompletionHandler
passed in from the native framework. When the nativecompletionHandler
is called inside thechildHandler
, the app crashes.I think this is due to the native
completionHandler
being released after theuserNotificationCenterWillPresentNotificationWithCompletionHandler
returns. The JS object that wraps the completionHandler is still there, but the underlying block is gone. I think this is the source of the EXC_BAD_ACCESS.I think in order to fix it, the
completionHandler
somehow needs to be retained in @nativescript/shared-notification-delegate so it does not get released. (I think in Objective-C,completionHandler
would need to be copied in order to be retained by another block)