Giter Site home page Giter Site logo

metalpapa / react-native-marketingcloudsdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from salesforce-marketingcloud/react-native-marketingcloudsdk

0.0 1.0 0.0 214 KB

The Official ReactNative Plugin for the Marketing Cloud MobilePush SDK.

License: BSD 3-Clause "New" or "Revised" License

Ruby 3.21% Java 41.42% JavaScript 21.12% Objective-C 32.77% Starlark 1.47%

react-native-marketingcloudsdk's Introduction

Salesforce Marketing Cloud React Native

Use this module to implement the Marketing Cloud MobilePush SDK for your iOS and Android applications.

Release Notes

Release notes for the plugin can be found here

Installation

1. Add plugin to your application via npm

npm install react-native-marketingcloudsdk --save

Android Setup

1. Add Marketing Cloud SDK repository

android/build.gradle

allprojects {
    repositories {
        maven { url "https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/repository" }
        //... Other repos
    }
}

2. Provide FCM credentials

  1. To enable push support for the Android platform you will need to include the google-services.json file. Download the file from your Firebase console and place it into the android/app directory

  2. Include the Google Services plugin in your build android/build.gradle

buildscript {
  repositories {
    google()  // Google's Maven repository
  }

  dependencies {
    // ...
    // Add the following line:
    classpath 'com.google.gms:google-services:4.2.0'
  }
}
  1. Apply the plugin android/app/build.gradle
// Add the following line to the bottom of the file:
apply plugin: 'com.google.gms.google-services

3. Configure the SDK in your MainApplication.java class

@Override
public void onCreate() {
    super.onCreate();

    MarketingCloudSdk.init(this,
            MarketingCloudConfig.builder()
                    .setApplicationId("{MC_APP_ID}")
                    .setAccessToken("{MC_ACCESS_TOKEN}")
                    .setSenderId("{FCM_SENDER_ID_FOR_MC_APP}")
                    .setMarketingCloudServerUrl("{MC_APP_SERVER_URL}")
                    .setNotificationCustomizationOptions(NotificationCustomizationOptions.create(R.drawable.ic_notification))
                    .setAnalyticsEnabled(true)
                    .build(this),
            initializationStatus -> Log.e("INIT", initializationStatus.toString()));

    // ... The rest of the onCreate method    
}

iOS Setup

1. Install pod for Marketing Cloud SDK

cd ios
pod install

2. Configure the SDK in your AppDelegate.m class

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    MarketingCloudSDKConfigBuilder *mcsdkBuilder = [MarketingCloudSDKConfigBuilder new];
    [mcsdkBuilder sfmc_setApplicationId:@"{MC_APP_ID}"];
    [mcsdkBuilder sfmc_setAccessToken:@"{MC_ACCESS_TOKEN}"];
    [mcsdkBuilder sfmc_setAnalyticsEnabled:@(YES)];
    [mcsdkBuilder sfmc_setMarketingCloudServerUrl:@"{MC_APP_SERVER_URL}"];

    NSError *error = nil;
    BOOL success =
        [[MarketingCloudSDK sharedInstance] sfmc_configureWithDictionary:[mcsdkBuilder sfmc_build]
                                                                   error:&error];

    // ... The rest of the didFinishLaunchingWithOptions method  
}

3. Enable Push

Follow these instructions to enable push for iOS.

API Reference

Kind: global class

MCReactModule.isPushEnabled() ⇒ Promise.<boolean>

The current state of the pushEnabled flag in the native Marketing Cloud SDK.

Kind: static method of MCReactModule
Returns: Promise.<boolean> - A promise to the boolean representation of whether push is enabled.
See

MCReactModule.enablePush()

Enables push messaging in the native Marketing Cloud SDK.

Kind: static method of MCReactModule
See

MCReactModule.disablePush()

Disables push messaging in the native Marketing Cloud SDK.

Kind: static method of MCReactModule
See

MCReactModule.getSystemToken() ⇒ Promise.<?string>

Returns the token used by the Marketing Cloud to send push messages to the device.

Kind: static method of MCReactModule
Returns: Promise.<?string> - A promise to the system token string.
See

MCReactModule.getAttributes() ⇒ Promise.<Object.<string, string>>

Returns the maps of attributes set in the registration.

Kind: static method of MCReactModule
Returns: Promise.<Object.<string, string>> - A promise to the key/value map of attributes set in the registration.
See

MCReactModule.setAttribute(key, value)

Sets the value of an attribute in the registration.

Kind: static method of MCReactModule
See

Param Type Description
key string The name of the attribute to be set in the registration.
value string The value of the key attribute to be set in the registration.

MCReactModule.clearAttribute(key)

Clears the value of an attribute in the registration.

Kind: static method of MCReactModule
See

Param Type Description
key string The name of the attribute whose value should be cleared from the registration.

MCReactModule.addTag(tag)

Kind: static method of MCReactModule
See

Param Type Description
tag string The tag to be added to the list of tags in the registration.

MCReactModule.removeTag(tag)

Kind: static method of MCReactModule
See

Param Type Description
tag string The tag to be removed from the list of tags in the registration.

MCReactModule.getTags() ⇒ Promise.<Array.<string>>

Returns the tags currently set on the device.

Kind: static method of MCReactModule
Returns: Promise.<Array.<string>> - A promise to the array of tags currently set in the native SDK.
See

MCReactModule.setContactKey(contactKey)

Sets the contact key for the device's user.

Kind: static method of MCReactModule
See

Param Type Description
contactKey string The value to be set as the contact key of the device's user.

MCReactModule.getContactKey() ⇒ Promise.<?string>

Returns the contact key currently set on the device.

Kind: static method of MCReactModule
Returns: Promise.<?string> - A promise to the current contact key.
See

MCReactModule.enableVerboseLogging()

Enables verbose logging within the native Marketing Cloud SDK.

Kind: static method of MCReactModule
See

MCReactModule.disableVerboseLogging()

Disables verbose logging within the native Marketing Cloud SDK.

Kind: static method of MCReactModule
See

MCReactModule.logSdkState()

Instructs the native SDK to log the SDK state to the native logging system (Logcat for Android and Xcode/Console.app for iOS). This content can help diagnose most issues within the SDK and will be requested by the Marketing Cloud support team.

Kind: static method of MCReactModule


3rd Party Product Language Disclaimers

Where possible, we changed noninclusive terms to align with our company value of Equality. We retained noninclusive terms to document a third-party system, but we encourage the developer community to embrace more inclusive language. We can update the term when it’s no longer required for technical accuracy.

react-native-marketingcloudsdk's People

Contributors

troach-sf avatar billmote avatar bcriscuolo-sf avatar skytan4 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.