diff --git a/docs/subscription.md b/docs/subscription.md new file mode 100644 index 0000000000000000000000000000000000000000..1b5038c6dbd1e7cbc60b656e0242e18c070edf8b --- /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 6972d718abd1b6317230193826b1de4169f14700..040c605a0da6e3f6b8a530c9943c435f110cc6a5 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 ca0e0f47a67c739cd7b473501e41170ebc6d80d9..1321381d15e387078f9b6924588931b359194410 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": {