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 theagconnect-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
andtargetSdkVersion
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'sapplication
section to receive notifications when the app is foreground.
If you are going to do Huawei integration, add the following lines to the file.
In order to send push to Huawei devices, you need to follow the steps in the link from the Huawei Developer panel. https://developer.huawei.com/consumer/en/doc/HMS-Plugin-Guides-V1/config-agc-0000001050178043-V1
Add below code to your
AndroidManifest.xml
file'sapplication
section to enable geofence capability.
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'sdidFinishLaunchingWithOptions
method and add the following just before return statement.
Modify
AppDelegate.m
and add following methods.
Modify
AppDelegate.m
file'sdidFinishLaunchingWithOptions
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 yourInfo.plist
file to be able to use AdvertisingTrackingID on iOS 14 and later. If you don't want to use it, setisIDFAEnabled
tofalse
among theinitRelatedDigital
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. SelectCreate folder references
when prompted.To enable rich notification capabilites like showing image or video;
Add
Notification Service Extension
target to your project and name itRelatedDigitalNotificationService
. Change this service's target iOS version to 10.0. Then change newly addedNotificationService.m
file contents with the following: (Don't forget to enter your app name instead ofAPP_ALIAS
)Add below lines to your Podfile's root level.
Modify Podfile and have the following in main target section.
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.Make sure your deployment target is ios 10.
Execute
pod install
then run.
To enable push notification carousel;
Add
Notification Content Extension
target to your project and name itRelatedDigitalNotificationContent
. 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.Add or replace the following lines in newly added
RelatedDigitalNotificationContent/Info.plist
Add below lines to your Podfile's root level.
In Xcode, select
RelatedDigitalNotificationContent
target and add below files toBuild Phases
->Copy Bundle Resources
section. SelectCreate folder references
when prompted.Make sure your deployment target is ios 10.
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 begroup.BUNDLE_ID.relateddigital
whereBUNDLE_ID
is the same as set inBundle 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 begroup.BUNDLE_ID.relateddigital
whereBUNDLE_ID
is the same as your Main App TargetBundle Identifier
. Do Not IncludeNotificationServiceExtension
andNotificationContentExtension
.Press OK
Copyright 2020 Related Digital