PushNotificationIOS

Projects with Native Code Only

This section only applies to projects made with react-native init
or to those made with Create React Native App which have since ejected. For
more information about ejecting, please see
the guide on
the Create React Native App repository.

cancelLocalNotifications()

Optionally restricts the set of canceled notifications to those notifications whose userInfo fields match the corresponding fields in the userInfo argument.

getScheduledLocalNotifications()

static getScheduledLocalNotifications(callback)

Gets the local notifications that are currently scheduled.

addEventListener()

static addEventListener(type, handler)

Attaches a listener to remote or local notification events while the app is running in the foreground or the background.

Valid events are:

notification : Fired when a remote notification is received. The handler will be invoked with an instance of PushNotificationIOS.

localNotification : Fired when a local notification is received. The handler will be invoked with an instance of PushNotificationIOS.

register: Fired when the user registers for remote notifications. The handler will be invoked with a hex string representing the deviceToken.

registrationError: Fired when the user fails to register for remote notifications. Typically occurs when APNS is having issues, or the device is a simulator. The handler will be invoked with {message: string, code: number, details: any}.

removeEventListener()

static removeEventListener(type, handler)

Removes the event listener. Do this in componentWillUnmount to prevent memory leaks

requestPermissions()

static requestPermissions(permissions?)

Requests notification permissions from iOS, prompting the user's dialog box. By default, it will request all notification permissions, but a subset of these can be requested by passing a map of requested permissions. The following permissions are supported:

alert

badge

sound

If a map is provided to the method, only the permissions with truthy values will be requested.

This method returns a promise that will resolve when the user accepts, rejects, or if the permissions were previously rejected. The promise resolves to the current state of the permission.

abandonPermissions()

You should call this method in rare circumstances only, such as when a new version of the app removes support for all types of remote notifications. Users can temporarily prevent apps from receiving remote notifications through the Notifications section of the Settings app. Apps unregistered through this method can always re-register.

checkPermissions()

static checkPermissions(callback)

See what push permissions are currently enabled. callback will be invoked with a permissions object:

alert :boolean

badge :boolean

sound :boolean

getInitialNotification()

static getInitialNotification()

This method returns a promise that resolves to either the notification object if the app was launched by a push notification, or null otherwise.

constructor()

constructor(nativeNotif);

You will never need to instantiate PushNotificationIOS yourself. Listening to the notification event and invoking getInitialNotification is sufficient

Call this to execute when the remote notification handling is complete. When calling this block, pass in the fetch result value that best describes the results of your operation. You must call this handler and should do so as soon as possible. For a list of possible values, see PushNotificationIOS.FetchResult.

If you do not call this method your background remote notifications could be throttled, to read more about it see the above documentation link.