0

I have followed the guide on the react-native-push-notification documentation (https://github.com/zo0r/react-native-push-notification) to a T, but I'm unable to generate a simple notification when I load the app on my phone. Instead, I can see the notification in the XCode console. There are no errors otherwise.

var PushNotification = require('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 );

        // process the notification

        // required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html)
        notification.finish(PushNotificationIOS.FetchResult.NoData);
    },

    // 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,
});

export default class PostList extends Component<{}> 
{
    componentDidMount() {
        PushNotification.localNotification({
              /* Android Only Properties */
              id: '0', // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
              ticker: "My Notification Ticker", // (optional)
              autoCancel: true, // (optional) default: true
              largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
              smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher"
              bigText: "My big text that will be shown when notification is expanded", // (optional) default: "message" prop
              subText: "This is a subText", // (optional) default: none
              color: "red", // (optional) default: system default
              vibrate: true, // (optional) default: true
              vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
              tag: 'some_tag', // (optional) add tag to message
              group: "group", // (optional) add group to message
              ongoing: false, // (optional) set whether this is an "ongoing" notification

              /* iOS and Android properties */
              title: "My Notification Title", // (optional, for iOS this is only used in apple watch, the title will be the app name on other iOS devices)
              message: "My Notification Message", // (required)
              playSound: false, // (optional) default: true
              soundName: 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
              number: '10', // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
              repeatType: 'day', // (Android only) Repeating interval. Could be one of `week`, `day`, `hour`, `minute, `time`. If specified as time, it should be accompanied by one more parameter 'repeatTime` which should the number of milliseconds between each interval
              actions: '["Yes", "No"]',  // (Android only) See the doc for notification actions to know more
          });
    }
}
3
  • Did you check permissions? Commented Dec 22, 2017 at 17:20
  • what is the exact iOS version of the device? Commented Dec 22, 2017 at 18:50
  • iOS 11.2.1 and I pressed "Allow" when my phone prompted me for permissions. Commented Dec 23, 2017 at 9:02

1 Answer 1

1

It turned out that the issue was that my Apple developer account needed to be a paid, subscriber account before I could use the notification system. I didn't realize that and for some reason didn't get any errors. Once I updated my account, the notifications started working.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.