React Native - Setup

 

Installation

  • Install prerequisites.

yarn add @react-native-async-storage/async-storage

or

npm i @react-native-async-storage/async-storage
  • Install package.

yarn add react-native-related-digital

or

 

  • Install pods (IOS only).

 

Platform Integrations

Android

  • Create a Firebase project and register your app. Download google-services.json file and place it in android/app folder.

  • Add below line to your android/build.gradle file's both repositories sections. If you are going to do Huawei integration, add the agconnect-services.json file to the same location.

  • Add below lines to your android/build.gradle file's dependencies section.

  • Change your minSdkVersion to 21.

  • Change your compileSdkVersion and targetSdkVersion to 32.

  • Add below lines to your android/app/build.gradle file's bottom.

  • Add below line to your android/app/build.gradle file's defaultConfig section.

  • Add below code to your AndroidManifest.xml file's application section to receive notifications when the app is foreground.

  • If you are going to do Huawei integration, add the following lines to the file.

  • Modify your MainApplication.java as below to init library. Change geofenceEnabled parameter as you want.

  • If you want to track installed apps, call below method.

Also, add one of the below sections to your AndroidManifest.xml

Option 1

Option 2

  • Add below listener to be able to handle carousel push notification's item click.

 

IOS

  • Enable Push Notifications and Background Modes->Remote Notifications capabilities.

  • Import library in AppDelegate.h

  • Modify AppDelegate.h and add UNUserNotificationCenterDelegate. (Classical React Native Project)

  • Modify AppDelegate.h and add UNUserNotificationCenterDelegate. (Expo Project)

  • Import libraries in AppDelegate.m

  • Modify AppDelegate.m file's didFinishLaunchingWithOptions method and add the following just before return statement.

  • Modify AppDelegate.m and add following methods.

  • Modify AppDelegate.m file's didFinishLaunchingWithOptions method and add the following just before return statement. Modify inAppNotificationsEnabled and geofenceEnabled parameters as you want.

  • Add Empty.swift file to your project as the sdk contains Swift code and xcode requires at least one empty swift file in each target.

  • Add NSUserTrackingUsageDescription to your Info.plist file to be able to use AdvertisingTrackingID on iOS 14 and later. If you don't want to use it, set isIDFAEnabled to false among the initRelatedDigital parameters.

  • If you have any issues while building the app due to _swift_getFunctionReplacement or any swift related errors, try editing your project's (not target) Library Search Paths and remove $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME) line.

  • If you are going to use in app notifications feature, add below lines to your project target's Build Phases->Copy Bundle Resources section. Select Create folder references when prompted.

  • To enable rich notification capabilites like showing image or video;

  1. Add Notification Service Extension target to your project and name it RelatedDigitalNotificationService. Change this service's target iOS version to 10.0. Then change newly added NotificationService.m file contents with the following: (Don't forget to enter your app name instead of APP_ALIAS)

     

  2. Add below lines to your Podfile's root level.

     

  3. Modify Podfile and have the following in main target section.

     

  4. Add Empty.swift file to your RelatedDigitalNotificationService target as the sdk contains Swift code and xcode requires at least one empty swift file in each target.

  5. Make sure your deployment target is ios 10.

     

  6. Execute pod install then run.

  • To enable push notification carousel;

  1. Add Notification Content Extension target to your project and name it RelatedDigitalNotificationContent. Change this service's target iOS version to 11.0. Remove newly added files under RelatedDigitalNotificationContent except Info.plist. Then add EMNotificationViewController.swift file with the following content.

     

  2. Add or replace the following lines in newly added RelatedDigitalNotificationContent/Info.plist

     

  3. Add below lines to your Podfile's root level.

     

  4. In Xcode, select RelatedDigitalNotificationContent target and add below files to Build Phases->Copy Bundle Resources section. Select Create folder references when prompted.

     

  5. Make sure your deployment target is ios 10.

     

  6. Execute pod install then run.

App Groups

Enable App Groups Capability for your targets. App Groups allow your app to execute code when a notification is recieved, even if your app is not active. This is required for Related Digital's analytics features and to store and access notification payloads of the last 30 days.

  • In your Main App Target go to Signing & Capabilities > All.

    Click + Capability if you do not have App Groups in your app yet.

  • Select App Groups.

  • Under App Groups click the + button.

    Set the App Groups container to be group.BUNDLE_ID.relateddigital where BUNDLE_ID is the same as set in Bundle Identifier.

  • Press OK.

  • In the NotificationServiceExtension Target

  • Go to Signing & Capabilities > All

    Click + Capability if you do not have App Groups in your app yet.

  • Select App Groups

  • In the NotificationContentExtension Target go to Signing & Capabilities > All`.

    Click + Capability.

  • Select App Groups

  • Under App Groups click the + button.

    Set the App Groups container to be group.BUNDLE_ID.relateddigital where BUNDLE_ID is the same as your Main App Target Bundle Identifier. Do Not Include NotificationServiceExtension and NotificationContentExtension.

  • Press OK

App Groups
App Groups Name

 

Copyright 2020 Related Digital