# react-native-grow-sdk-beta

> Grow your app by engaging your users

Latest version **1.0.0-beta.185** (published 2023-12-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-grow-sdk-beta
pnpm add react-native-grow-sdk-beta
yarn add react-native-grow-sdk-beta
bun add react-native-grow-sdk-beta
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; large bundle.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-beta.185 |
| Published | 2023-12-06 |
| First published | 2022-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.7 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Bryj.ai |
| Maintainers | bryjai |
| Keywords | react-native, analytics, engagement, users, push, ios, android |

## Links

- npm: https://www.npmjs.com/package/react-native-grow-sdk-beta
- Homepage: https://www.bryj.ai
- npm.io page: https://npm.io/package/react-native-grow-sdk-beta

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.0-beta.185 (latest) — 2023-12-06
- 0.1.0 — 2023-01-30
- 0.0.4 — 2022-12-19
- 0.0.3 — 2022-12-19
- 0.0.2 — 2022-12-19
- 0.0.1 — 2022-11-17

## README

# Grow SDK for React Native v1.0.0-beta.185

## Requirements

- React Native >= 0.60
- iOS version > 11.0
- Cocoapods (iOS)
- Gradle (Android) 

## Installation of the SDK

Run this installation command from your project root directory:

`$ npm install react-native-grow-sdk-beta`

### For iOS

1. Run `pod install` in `YOUR_PROJECT/ios`:

```console
$ cd ios
$ pod install
```

2. 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](https://developer.apple.com/documentation/usernotifications/registering_your_app_with_apns)
- [Background Modes](https://developer.apple.com/documentation/xcode/configuring-background-execution-modes). Select options **Background fetch**, **Remote notifications**, and **Background processing**.
- [App Group](https://developer.apple.com/documentation/xcode/configuring-app-groups)

**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](https://developer.apple.com/documentation/xcode/capabilities).

### For Android

Add the Grow SDK maven repository in your top-level build.gradle file:

```groovy
allprojects {
    repositories {
        // ...
        maven {
            url 'https://nexus.bryj.ai/repository/releases/'
        }
    }
}
```

## Initializing the SDK

To initialize the SDK, it is required an **API Key** provided by the platform.

### For iOS

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:

```objective-c
#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:

```objective-c
- (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;
}
```

### For Android

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**

```java
public class MyApplication extends Application {
    
    @Override
    public void onCreate() {
        super.onCreate();
        Grow.start(getApplicationContext(),
                new Grow.ConfigurationBuilder("YOUR_API_KEY")
                        .build());
    }
}
```

**Kotlin**

```kotlin
class MyApplication : Application() {
    
    override fun onCreate() {
        super.onCreate()
        
        Grow.start(
            applicationContext,
            Grow.ConfigurationBuilder(apiKey = "YOUR_API_KEY")
                .build()
        )
    }
}
```

## Setup Push Notification

### For iOS

In order to handle Grow Push campaigns, you must add a [**Notification Service** extension](https://developer.apple.com/documentation/usernotifications/modifying_content_in_newly_delivered_notifications) 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`:

```swift
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()
    }
}
```

```objective-c
#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
```

## For Android

If you haven't done so yet, you will need to [register your app with Firebase](https://firebase.google.com/docs/android/setup#register-app) and to [add the Firebase configuration file to your project](https://firebase.google.com/docs/android/setup#add-config-file). To do so, follow the instructions from the official [Firebase documentation](https://firebase.google.com/docs/android/setup).

1. Add the Google Services plugin to the top-level build.gralde file:

    ```groovy
    buildscript {
        // ..
        dependencies {
            // ...
            classpath("com.google.gms:google-services:4.3.15")
        }
    }
    ```
    
2. Add the Firebase Cloud Messaging library dependency in your app-level `build.gradle` file:

    ```groovy
    dependencies {
        // ...
        implementation platform('com.google.firebase:firebase-bom:29.0.0')
        implementation 'com.google.firebase:firebase-messaging-ktx'
    }
    ```

2. Create a class which extends `FirebaseMessagingService` and override `onMessageReceived` and `onNewToken` as following:

    **Java**

    ```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**

    ```kotlin
    class MyFirebaseMessagingService : FirebaseMessagingService() {

        override fun onNewToken(token: String) {
            Grow.Device.setFirebasePushToken(token)
        }

        override fun onMessageReceived(message: RemoteMessage) {
            Grow.Device.processFirebaseMessage(message)
        }
    }
    ```    

3. Add the service previously created to the `AndroidManifest` inside your `<application>` tag. Make sure to set `android:name` to the relative path to your service:

    ```XML
    <service
        android:name=".MyFirebaseMessagingService"
        android:enabled="true"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
    ```

---
_Source: https://npm.io/package/react-native-grow-sdk-beta · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
