- React Native >= 0.60
- iOS version > 11.0
- Cocoapods (iOS)
- Gradle (Android)
Run this installation command from your project root directory:
$ npm install react-native-grow-sdk-beta
- Run
pod install
inYOUR_PROJECT/ios
:
$ cd ios
$ pod install
- Configure Xcode Signing & Capabilities
In order to make the SDK fully functional, it requires the developer to configure capabilities on the Application target and as well on the Extension target. Enable the following capabilities:
- Push Notifications
- Background Modes. Select options Background fetch, Remote notifications, and Background processing.
- App Group
Caution: the App Group
name needs to be the same on both Application and Extension targets.
To learn more about capabilities please check Apple documentation.
Add the Grow SDK maven repository in your top-level build.gradle file:
allprojects {
repositories {
// ...
maven {
url 'https://nexus.bryj.ai/repository/releases/'
}
}
}
To initialize the SDK, it is required an API Key provided by the platform.
You need to [configure the App Group](# Installation of the SDK) on your Xcode project. Without the App Group, the SDK will not provide "Push+Landing" campaigns to your application.
In your AppDelegate class file, import the GrowSDK framework:
#import <GrowSDK/GrowSDK-Swift.h>
Still in this AppDelegate
file find the method application(_:didFinishLaunchingWithOptions:)
and on it create a AppConfigurationBuilder instance from the GrowSDK framework. This instance will allow you to generate through the build()
method the required AppConfiguration to be passed in the static method start(_:options:)
of the main class Grow
. This static method also requires the launchOptions.
In the example below, a AppConfigurationBuilder
is instantiated with the mandatory apiKey
provided by the platform, and the mandatory appGroup
configured by the developer on Xcode:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
id <AppConfiguration> configuration = [[[AppConfigurationBuilder alloc]
initWithApiKey:@"YOUR_API_KEY"
appGroup:@"YOUR_APP_GROUP"]
build];
[Grow startWithConfiguration:configuration options:launchOptions];
// ...
return YES;
}
In your Application class file, call Grow.start(Context, Grow.Configuration)
from your Application.onCreate()
implementation. The Grow.Configuration
required to initialize the SDK is provided by the Grow.ConfigurationBuilder
thanks the to build()
method.
In the example below, a Grow.Configuration
is instantiated with the mandatory apiKey
set to a string provided by the platform:
Java
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Grow.start(getApplicationContext(),
new Grow.ConfigurationBuilder("YOUR_API_KEY")
.build());
}
}
Kotlin
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
Grow.start(
applicationContext,
Grow.ConfigurationBuilder(apiKey = "YOUR_API_KEY")
.build()
)
}
}
In order to handle Grow Push campaigns, you must add a Notification Service extension to your app. Then go to your project configuration and select your Extension Target. From the Frameworks and Libraries add the GrowSDK.xcframework and select Do Not Embed.
From the auto-generated files open the main Notification Service class that extends from UNNotificationServiceExtension
and find the method didReceive(_:withContentHandler:)
. Inside this method create a ExtensionConfigurationBuilder instance from the GrowSDK framework passing mandatory fields apiKey
, appGroup
, and appBundleIdentifier
. This instance will allow you to generate through the build()
method the required ExtensionConfiguration to be passed in the static method didReceive(_:forConfiguration:withContentHandler:)
of the main class Grow
. This static method will return a GrowNotificationService object that you will need to save a reference to be able to forward the serviceExtensionTimeWillExpire()
from Apple in case it times out.
Your extension class must look like one of the following depending if you choose Swift
or Objective-C
:
import UserNotifications
import GrowSDK
class NotificationService: UNNotificationServiceExtension {
var service: GrowNotificationService?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
let configuration = Grow.ExtensionConfigurationBuilder(appGroup: "YOUR_APP_GROUP",
appBundleIdentifier: "YOUR_APP_BUNDLE_IDENTIFIER")
.build()
service = Grow.didReceive(request, forConfiguration: configuration, withContentHandler: contentHandler)
}
override func serviceExtensionTimeWillExpire() {
service?.serviceExtensionTimeWillExpire()
}
}
#import <GrowSDK/GrowSDK-Swift.h>
@interface NotificationService ()
@property (nonatomic, strong) GrowNotificationService *service;
@end
@implementation NotificationService
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
id <ExtensionConfiguration> configuration = [[[ExtensionConfigurationBuilder alloc]
initAppGroup:@"YOUR_APP_GROUP"
appBundleIdentifier:@"YOUR_APP_BUNDLE_IDENTIFIER"]
build];
self.service = [Grow didReceive:request forConfiguration:configuration withContentHandler:contentHandler];
}
- (void)serviceExtensionTimeWillExpire {
[self.service serviceExtensionTimeWillExpire];
}
@end
If you haven't done so yet, you will need to register your app with Firebase and to add the Firebase configuration file to your project. To do so, follow the instructions from the official Firebase documentation.
-
Add the Google Services plugin to the top-level build.gralde file:
buildscript { // .. dependencies { // ... classpath("com.google.gms:google-services:4.3.15") } }
-
Add the Firebase Cloud Messaging library dependency in your app-level
build.gradle
file:dependencies { // ... implementation platform('com.google.firebase:firebase-bom:29.0.0') implementation 'com.google.firebase:firebase-messaging-ktx' }
-
Create a class which extends
FirebaseMessagingService
and overrideonMessageReceived
andonNewToken
as following:Java
public class MyFirebaseMessagingService extends FirebaseMessagingService { @Override public void onNewToken(@NonNull String token) { super.onNewToken(token); Grow.Device.setFirebasePushToken(token); } @Override public void onMessageReceived(@NonNull RemoteMessage message) { super.onMessageReceived(message); Grow.Device.processFirebaseMessage(message); } }
Kotlin
class MyFirebaseMessagingService : FirebaseMessagingService() { override fun onNewToken(token: String) { Grow.Device.setFirebasePushToken(token) } override fun onMessageReceived(message: RemoteMessage) { Grow.Device.processFirebaseMessage(message) } }
-
Add the service previously created to the
AndroidManifest
inside your<application>
tag. Make sure to setandroid:name
to the relative path to your service:<service android:name=".MyFirebaseMessagingService" android:enabled="true" android:exported="false"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>