- Created by Andrey Veprikov, last modified on Oct 13, 2022
You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 21 Next »
Installation
The RN SDK is available for installation from GitHub and NPM. Run one of the following commands in the terminal to install it.
yarn add @personaclick/rn-sdk
or
yarn add https://github.com/PersonaClick/rn-sdk.git
Additionally, the following components must be installed:
yarn add @react-native-async-storage/async-storage yarn add react-native-device-info yarn add react-native-push-notification yarn add @react-native-community/push-notification-ios yarn add @react-native-firebase/app yarn add @react-native-firebase/messaging
Additional Installation for iOS
Add Capabilities : Background Mode - Remote Notifications
Go into your MyReactProject/ios
dir and open MyProject.xcworkspace
workspace. Select the top project "MyProject" and select the "Signing & Capabilities" tab. Add a 2 new Capabilities using "+" button:
Background Mode
capability and tickRemote Notifications
Push Notifications
capability
Update AppDelegate.h
At the top of the file:
#import <UserNotifications/UNUserNotificationCenter.h>
Then, add the 'UNUserNotificationCenterDelegate' to protocols:
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate>
Update AppDelegate.m
At the top of the file:
#import <UserNotifications/UserNotifications.h> #import <RNCPushNotificationIOS.h> #import <Firebase.h>
Then, add the following lines:
// Required for the register event. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } // Required for the notification event. You must call the completion handler after handling the remote notification. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; } // Required for the registrationError event. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error]; } // Required for localNotification event - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { [RNCPushNotificationIOS didReceiveNotificationResponse:response]; }
And then in your AppDelegate implementation, add the following:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... // Define UNUserNotificationCenter UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; return YES; } //Called when a notification is delivered to a foreground app. -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge); }
Open a terminal window and navigate to the location of the Xcode project for your app
cd ios/ pod install
Background Application State
iOS Background Limitation
On iOS devices, the user is able to toggle Background App Refresh in device's Settings. Furthermore, the Background App Refresh setting will automatically be off if the device is in low power mode.
If the iOS Background App Refresh mode is off, the handler configured in setBackgroundMessageHandler
won't be triggered.
On iOS, when when Firebase is used and a message is received the device silently starts your application in a background state. To get around this problem, you can configure your application. Use this property to conditionally render null ("nothing") if your app is launched in the background:
// index.js import { AppRegistry } from 'react-native'; function HeadlessCheck({ isHeadless }) { if (isHeadless) { // App has been launched in the background by iOS, ignore return null; } return <App />; } function App() { // Your application } AppRegistry.registerComponent('app', () => HeadlessCheck);
To inject a isHeadless prop into your app, please update your AppDelegate.m file as instructed below:
// add this import statement at the top of your `AppDelegate.m` file #import "RNFBMessagingModule.h" // in "(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions" method // Use `addCustomPropsToUserProps` to pass in props for initialization of your app // Or pass in `nil` if you have none as per below example // For `withLaunchOptions` please pass in `launchOptions` object NSDictionary *appProperties = [RNFBMessagingModule addCustomPropsToUserProps:nil withLaunchOptions:launchOptions]; // Find the `RCTRootView` instance and update the `initialProperties` with your `appProperties` instance RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"nameOfYourApp" initialProperties:appProperties];
Additional Installation for Android
Add the google-services plugin to your android/build.gradle
file:
buildscript { dependencies { classpath 'com.google.gms:google-services:4.3.4' // ... } // ... }
Also add the following to the android/app/build.gradle
file:
apply plugin: 'com.google.gms.google-services'
Page Navigation
Related Pages
-
Page:
-
Page:
-
Page:
-
Page:
- No labels