I am trying to migrate from PushNotificationIOS to this package because it uses the new UserNotifications framework from iOS. I followed the steps in the documentation and added a sample notification to my app. When I try to show the sample notification and the app is in foreground, the app crashes with message TypeError: undefined is not an object (evaluating 'this.alert.title'). If I set a fireDate and keep the app in background when the notification arrives, then I see the notification and app doesn't crash. I used the below code to post the local notification
let someLocalNotification = Notifications.postLocalNotification({
fireDate: Date.now() + 5000,
body: 'Local notificiation!',
title: 'Local Notification Title',
sound: 'chime.aiff',
userInfo: {}
})
same problem
i have the same problem when trying to use postLocalNotification in ios:
Notifications.postLocalNotification({
body: 'Local notificiation!',
title: 'Local Notification Title',
sound: 'default',
silent: false
});
i get TypeError: Cannot read property 'title' of undefined
I'm getting this error in the example app
all problems solved in https://github.com/zo0r/react-native-push-notification work on android and ios. Enable foreground https://github.com/react-native-community/react-native-push-notification-ios/issues/63
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Just created a pull request to fix this. Since it seems like PRs are not being reviewed at this time, here is a patch that you can apply using patch-package:
Here's the patch:
diff --git a/node_modules/react-native-notifications/lib/dist/DTO/Notification.js b/node_modules/react-native-notifications/lib/dist/DTO/Notification.js
index 8f79edc..c23b09f 100644
--- a/node_modules/react-native-notifications/lib/dist/DTO/Notification.js
+++ b/node_modules/react-native-notifications/lib/dist/DTO/Notification.js
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
class Notification {
constructor(payload) {
this.payload = payload;
+ this.identifier = payload.identifier;
}
get title() {
return this.payload.title;
diff --git a/node_modules/react-native-notifications/lib/dist/DTO/NotificationFactory.js b/node_modules/react-native-notifications/lib/dist/DTO/NotificationFactory.js
index ae41826..d8d95cf 100644
--- a/node_modules/react-native-notifications/lib/dist/DTO/NotificationFactory.js
+++ b/node_modules/react-native-notifications/lib/dist/DTO/NotificationFactory.js
@@ -1,12 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
+const Notification_1 = require("./Notification");
const NotificationIOS_1 = require("./NotificationIOS");
const NotificationAndroid_1 = require("./NotificationAndroid");
const react_native_1 = require("react-native");
class NotificationFactory {
fromPayload(payload) {
if (react_native_1.Platform.OS === 'ios') {
- return new NotificationIOS_1.NotificationIOS(payload);
+ return payload.aps ? new NotificationIOS_1.NotificationIOS(payload) : new Notification_1.Notification(payload);
}
else {
return new NotificationAndroid_1.NotificationAndroid(payload);
Facing this issue!
would be great to have https://github.com/wix/react-native-notifications/pull/537 merged !
i'm getting the same error!
My app keep crashing when receiving notification on foreground!
Most helpful comment
I'm getting this error in the example app