From ff096c8c392dbe261e01767fa7f11a1f25372a8b Mon Sep 17 00:00:00 2001 From: yogevbd Date: Wed, 2 Oct 2019 16:31:28 +0300 Subject: [PATCH] Add subscription documentation guide --- docs/subscription.md | 45 +++++++++++++++++++++++++++++++++++++++++++ website/i18n/en.json | 5 +++++ website/sidebars.json | 1 + 3 files changed, 51 insertions(+) create mode 100644 docs/subscription.md diff --git a/docs/subscription.md b/docs/subscription.md new file mode 100644 index 0000000..1b5038c --- /dev/null +++ b/docs/subscription.md @@ -0,0 +1,45 @@ +--- +id: subscription +title: Push Notifications Subscription +sidebar_label: Subscription +--- + +The typical flow for subscribing a device for receiving push notification in real time is to first register the device at the vendor's servers (e.g. FCM), then publishing the received token to your own push management servers. + +This section is about the first part of the flow. + +In order to handle notifications, you must register the `remoteNotificationsRegistered` event beforehand. + + +In your React Native app: + +```javascript +import {Notifications} from 'react-native-notifications'; + +class App extends Component { + constructor() { + Notifications.events().registerRemoteNotificationsRegistered((event: Registered) => { + // TODO: Send the token to my server so it could send back push notifications... + console.log("Device Token Received", event.deviceToken); + }); + Notifications.events().registerRemoteNotificationsRegistrationFailed((event: RegistrationError) => { + console.error(event); + }); + + Notifications.requestPermissions(); + } +} + +``` + +When you have the device token, POST it to your server and register the device in your notifications provider (Amazon SNS, Azure, etc.). + +You can check if the user granted permissions on iOS by calling `checkPermissions()`: + +```javascript +Notifications.ios.checkPermissions().then((currentPermissions) => { + console.log('Badges enabled: ' + !!currentPermissions.badge); + console.log('Sounds enabled: ' + !!currentPermissions.sound); + console.log('Alerts enabled: ' + !!currentPermissions.alert); +}); +``` diff --git a/website/i18n/en.json b/website/i18n/en.json index 6972d71..040c605 100644 --- a/website/i18n/en.json +++ b/website/i18n/en.json @@ -40,6 +40,10 @@ "notification-object": { "title": "Notification object", "sidebar_label": "Notification" + }, + "subscription": { + "title": "Push Notifications Subscription", + "sidebar_label": "Subscription" } }, "links": { @@ -48,6 +52,7 @@ }, "categories": { "Installation": "Installation", + "Guides": "Guides", "Advanced": "Advanced", "Commands": "Commands", "Events": "Events", diff --git a/website/sidebars.json b/website/sidebars.json index ca0e0f4..1321381 100755 --- a/website/sidebars.json +++ b/website/sidebars.json @@ -1,6 +1,7 @@ { "docs": { "Installation": ["installation-ios", "installation-android"], + "Guides": ["subscription"], "Advanced": ["advanced-ios"] }, "api": { -- 2.26.2