general-events.md 2 KB
Newer Older
yogevbd's avatar
yogevbd committed
1 2
---
id: general-events
yogevbd's avatar
yogevbd committed
3 4
title: General
sidebar_label: General
yogevbd's avatar
yogevbd committed
5 6
---

yogevbd's avatar
yogevbd committed
7 8
## registerRemoteNotificationsRegistered()
Fired when the user registers for remote notifications. The handler will be invoked with an event holding the hex string representing the `deviceToken`
yogevbd's avatar
yogevbd committed
9 10

```js
yogevbd's avatar
yogevbd committed
11 12 13
Notifications.events().registerRemoteNotificationsRegistered((event: Registered) => {
  console.log(event.deviceToken);
});
yogevbd's avatar
yogevbd committed
14 15
```

yogevbd's avatar
yogevbd committed
16
## registerNotificationReceived()
17
Fired when a remote notification is received in foreground state. The handler will be invoked with an instance of [Notification](http://localhost:3000/react-native-notifications/docs/notification-object).
yogevbd's avatar
yogevbd committed
18
Should call completion function on iOS, will be ignored on Android.
yogevbd's avatar
yogevbd committed
19 20

```js
yogevbd's avatar
yogevbd committed
21 22 23 24 25 26
Notifications.events().registerNotificationReceived((notification: Notification, completion: (response: NotificationCompletion) => void) => {
  console.log(JSON.stringify(notification.data));

  // Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
  completion({alert: true, sound: true, badge: false});
});
yogevbd's avatar
yogevbd committed
27 28
```

yogevbd's avatar
yogevbd committed
29
## registerRemoteNotificationOpened()
30
Fired when a remote notification is opened from dead or background state. The handler will be invoked with an instance of [Notification](http://localhost:3000/react-native-notifications/docs/notification-object).
yogevbd's avatar
yogevbd committed
31
Should call completion function on iOS, will be ignored on Android.
yogevbd's avatar
yogevbd committed
32 33

```js
yogevbd's avatar
yogevbd committed
34
Notifications.events().registerRemoteNotificationOpened((notification: Notification, completion: () => void) => {
yogevbd's avatar
yogevbd committed
35
  console.log(JSON.stringify(notification.data));
yogevbd's avatar
yogevbd committed
36
  completion();
yogevbd's avatar
yogevbd committed
37
});
yogevbd's avatar
yogevbd committed
38 39
```

yogevbd's avatar
yogevbd committed
40 41
## registerRemoteNotificationsRegistrationFailed()
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 {localizedDescription: string, code: string, domain: string}.
yogevbd's avatar
yogevbd committed
42 43

```js
yogevbd's avatar
yogevbd committed
44 45
Notifications.events().registerRemoteNotificationsRegistrationFailed((event: RegistrationError) => {
  console.log(event.code, event.localizedDescription, event.domain);
yogevbd's avatar
yogevbd committed
46 47
});
```