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

yogevbd's avatar
yogevbd committed
7 8 9 10 11 12 13 14 15
## registerRemoteNotifications()
Requests remote notification permissions, prompting the user's dialog box on iOS and request a token on Android.
If the user accept the remote notifications permissions, `RemoteNotificationsRegistered` event will get called with the device token.

```js
Notifications.registerRemoteNotifications();
```

## getInitialNotification()
16
This method returns a promise. If the app was launched by a push notification, this promise resolves to an object of type [Notification](notification-object). Otherwise, it resolves to undefined.
yogevbd's avatar
yogevbd committed
17 18

```js
19
const notification: Notification = await Notifications.getInitialNotification();
yogevbd's avatar
yogevbd committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
```

## postLocalNotification(notification, id?)
Posts local notification to the device notification center.

```js
Notifications.postLocalNotification({
  body: 'Local notificiation!',
  title: 'Local Notification Title',
  sound: 'chime.aiff',
  category: 'SOME_CATEGORY',
  link: 'localNotificationLink',
  fireDate: new Date()
}, id);
```

## cancelLocalNotification(id)
Relevant for notifications sent with `fireDate`.

```js
Notifications.cancelLocalNotification(id);
```

## isRegisteredForRemoteNotifications()
Check if the app has permissions to send remote notifications.

```js
47
const hasPermissions: boolean = await Notifications.getInitialNotification();
yogevbd's avatar
yogevbd committed
48
```