Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose setPushToken method to react-native lib #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Follow [these instructions](./ios_push.md) to enable push for iOS.
* [.enablePush()](#MCReactModule.enablePush)
* [.disablePush()](#MCReactModule.disablePush)
* [.getSystemToken()](#MCReactModule.getSystemToken) ⇒ <code>Promise.&lt;?string&gt;</code>
* [.setPushToken(token)](#MCReactModule.setPushToken)
* [.getAttributes()](#MCReactModule.getAttributes) ⇒ <code>Promise.&lt;Object.&lt;string, string&gt;&gt;</code>
* [.setAttribute(key, value)](#MCReactModule.setAttribute)
* [.clearAttribute(key)](#MCReactModule.clearAttribute)
Expand Down Expand Up @@ -182,6 +183,23 @@ the device.
- [Android Docs](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/6.0/reference/com/salesforce/marketingcloud/messages/push/PushMessageManager.html#getPushToken())
- [iOS Docs](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-iOS/appledoc/Classes/MarketingCloudSDK.html#//api/name/sfmc_deviceToken)

<a name="MCReactModule.setPushToken"></a>

### MCReactModule.setPushToken(token)
Set the Firebase or APN token used by the Marketing Cloud to send push messages to
the device.

**Kind**: static method of [<code>MCReactModule</code>](#MCReactModule)
**See**

- [Android Docs](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/MarketingCloudSdk/7.4/com.salesforce.marketingcloud.messages.push/-push-message-manager/set-push-token.html)
- [iOS Docs](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-iOS/appledoc/Classes/MarketingCloudSDK.html#/c:objc(cs)MarketingCloudSDK(im)sfmc_setDeviceToken:)


| Param | Type | Description |
| --- | --- | --- |
| token | <code>string</code> | The Firebase or APN token to be used by Marketing Cloud |

<a name="MCReactModule.getAttributes"></a>

### MCReactModule.getAttributes() ⇒ <code>Promise.&lt;Object.&lt;string, string&gt;&gt;</code>
Expand Down Expand Up @@ -327,8 +345,5 @@ the SDK and will be requested by the Marketing Cloud support team.

**Kind**: static method of [<code>MCReactModule</code>](#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.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ void execute(MarketingCloudSdk sdk, @NonNull Promise promise) {
});
}

@ReactMethod
public void setPushToken(final String token) {
handleAction(new Action() {
@Override
void execute(MarketingCloudSdk sdk) {
sdk.getPushMessageManager().setPushToken(token);
}
});
}

@ReactMethod
public void getAttributes(Promise promise) {
handleAction(new PromiseAction(promise) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ public void getSystemToken() {
verify(promise).resolve("token");
}

@Test
public void setPushToken() {
// GIVEN
ShadowMarketingCloudSdk.isReady(true);

// WHEN
reactModule.setPushToken("new-token");

// THEN
verify(pushMessageManager).setPushToken("new-token");
}

@Test
public void getAttributes() {
// GIVEN
Expand Down
4 changes: 4 additions & 0 deletions ios/RNMarketingCloudSdk.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ - (void)splitLog:(NSString *)msg {
resolve(deviceToken);
}

RCT_EXPORT_METHOD(setPushToken : (NSString *_Nonnull)token) {
[[MarketingCloudSDK sharedInstance] sfmc_setDeviceToken:token];
}

RCT_EXPORT_METHOD(setContactKey : (NSString *_Nonnull)contactKey) {
[[MarketingCloudSDK sharedInstance] sfmc_setContactKey:contactKey];
}
Expand Down
11 changes: 11 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ class MCReactModule {
return RNMarketingCloudSdk.getSystemToken();
}

/**
* Set the Firebase or APN token used by the Marketing Cloud to send push messages to
* the device.
* @param {string} token - The Firebase or APN token to be used by Marketing Cloud
* @see {@link https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/MarketingCloudSdk/7.4/com.salesforce.marketingcloud.messages.push/-push-message-manager/set-push-token.html|Android Docs}
* @see {@link https://salesforce-marketingcloud.github.io/MarketingCloudSDK-iOS/appledoc/Classes/MarketingCloudSDK.html#/c:objc(cs)MarketingCloudSDK(im)sfmc_setDeviceToken:|iOS Docs}
*/
static setPushToken(token) {
RNMarketingCloudSdk.setPushToken(token);
}

/**
* Returns the maps of attributes set in the registration.
* @returns {Promise<Object.<string, string>>} A promise to the key/value map of attributes set
Expand Down