How it works...

The recipe we built here is a little contrived, but the core concepts needed to request permissions, register tokens, accept app data, and send push notifications in response to app data are all there.

In step 4, we defined the first part of the registerForPushNotificationsAsync function. We began by asking the user for their permission to send them notifications from our app via the Permissions.askAsync method, passing in the constant for the push notifications permission, Permissions.NOTIFICATIONS. We then saved the status property from the resolved return object, which will have the value 'granted' if the user granted permission. If we don't get permission, we return right away; otherwise, we get the token from Expo's ...

Get React Native Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.