Step 4. Configuring React Native apps for push notifications
PingOne Advanced Identity Cloud PingAM React Native
In this step, you configure your React Native project to support push notifications on both Android and iOS.
Configuring Android for push notifications
To enable push notifications on Android, you add the Firebase configuration file to your project and apply the Google services Gradle plugin.
-
In Android Studio, open the
androiddirectory of your React Native project and switch to the Project view. -
Copy the
google-services.jsonfile that you downloaded from the Firebase console into theandroid/appdirectory of your project. -
To make the file available to the app, add the Google services Gradle plugin (
com.google.gms.google-services) as a dependency to your project.-
In your root-level Gradle file (
android/build.gradleorandroid/build.gradle.kts):-
Kotlin
-
Groovy
android/build.gradle.ktsplugins { // ... // Add the dependency for the Google services Gradle plugin id("com.google.gms.google-services") version "4.4.2" apply false }android/build.gradleplugins { // ... // Add the dependency for the Google services Gradle plugin id 'com.google.gms.google-services' version '4.4.2' apply false } -
-
In your app-level Gradle file (
android/app/build.gradleorandroid/app/build.gradle.kts):-
Kotlin
-
Groovy
android/app/build.gradle.ktsplugins { // ... // Add the Google services Gradle plugin id("com.google.gms.google-services") }android/app/build.gradleplugins { // ... // Add the Google services Gradle plugin id 'com.google.gms.google-services' } -
-
-
Add the
android.permission.POST_NOTIFICATIONSpermission inside the<manifest>element in theandroid/app/src/main/AndroidManifest.xmlfile:Adding post notification permission toAndroidManifest.xml<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
Configuring iOS for push notifications
To enable push notifications on iOS, you verify that the Push Notifications capability is enabled for your app in Xcode, and confirm it in the Apple Developer console.
-
In Xcode, open the
iosdirectory of your React Native project. -
In the Project navigator, select the project root.
-
In the editor, under Targets, click your application, then click the Signing & Capabilities tab.
-
Confirm that the application has the Push Notifications capability. If not, click + Capability to add it.
-
With an admin account, log in to the Apple Developer console.
-
Navigate to Program resources > Certificates, IDs & Profiles > Identifiers.
-
Click the name of the application to which you are adding push notification support.
-
On the Capabilities tab, ensure Push Notifications is selected.