React-native-push-notification: PushNotification.localNotificationSchedule is not working. What am I missing ?

Created on 2 Feb 2017  路  3Comments  路  Source: zo0r/react-native-push-notification

Here is my code, I try to fire it up with and without event but nothing seems to be happening, meanwhile PushNotification.localNotification is working perfectly.

    ...
    import PushNotification from 'react-native-push-notification';
    PushNotification.configure({

    // (optional) Called when Token is generated (iOS and Android)
    onRegister: function(token) {
        console.log( 'TOKEN:', token );
    },

    // (required) Called when a remote or local notification is opened or received
    onNotification: function(notification) {
        console.log( 'NOTIFICATION:', notification );
    },

    // ANDROID ONLY: GCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications) 
    senderID: "YOUR GCM SENDER ID",

    // IOS ONLY (optional): default: all - Permissions to register.
    permissions: {
        alert: true,
        badge: true,
        sound: true
    },

    // Should the initial notification be popped automatically
    // default: true
    popInitialNotification: true,

    /**
      * (optional) default: true
      * - Specified if permissions (ios) and token (android and ios) will requested or not,
      * - if not, you must call PushNotificationsHandler.requestPermissions() later
      */
    requestPermissions: true,
});

PushNotification.localNotificationSchedule({
    message: "My Scheduled Notification Message", // (required)
    date: new Date(Date.now() + (5 * 1000)), // in 60 secs
});

...

render() {
    ...
    function notif() {
            PushNotification.localNotificationSchedule({
                message: "My Notification Message", // (required)
                date: new Date(Date.now() + (1 * 1000)), // in 60 secs
            });
    }
     return(
          <TouchableOpacity onPress={notif}>
                    <Text style={styles.reminderButton}>R</Text>
                </TouchableOpacity>
      )
}

`
```

Most helpful comment

@edwinharly I've created a repo for demoing local and scheduled notifications [1]. As @ryanhomer said, you need to update the AndroidManifest.xml for scheduled notifications to work [2].

[1] https://github.com/sheshbabu/RNLocalScheduledNotificationDemo
[2] https://github.com/sheshbabu/RNLocalScheduledNotificationDemo/commit/a08628f50ffef1f7dac855773f58f29131245419

All 3 comments

Not sure what platform you're having issues with; I've only tried on Android so far. If it's on Android, have you updated your AndroidManifest.xml file? react-native link doesn't do this for you, so the instructions for this shouldn't appear only in the 'manual install' section. Don't forget to react-native run-android again afterwards. Also note that I was able to get localNotification() to work without modifying AndroidManifest.xml but not localNotificationSchedule().

@edwinharly I've created a repo for demoing local and scheduled notifications [1]. As @ryanhomer said, you need to update the AndroidManifest.xml for scheduled notifications to work [2].

[1] https://github.com/sheshbabu/RNLocalScheduledNotificationDemo
[2] https://github.com/sheshbabu/RNLocalScheduledNotificationDemo/commit/a08628f50ffef1f7dac855773f58f29131245419

@ryanhomer @sheshbabu it's working now, I forgot to update my AndroidManifest.xml, thank you guys for your help.

Was this page helpful?
0 / 5 - 0 ratings