Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ public void disableDeviceForCurrentUser() {
IterableApi.getInstance().disablePush();
}

public void registerForPush() {
IterableLogger.v(TAG, "registerForPush");
IterableApi.getInstance().registerForPush();
}

public void handleAppLink(String uri, Promise promise) {
IterableLogger.printInfo();
promise.resolve(IterableApi.getInstance().handleAppLink(uri));
Expand Down
5 changes: 5 additions & 0 deletions android/src/newarch/java/com/RNIterableAPIModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ public void disableDeviceForCurrentUser() {
moduleImpl.disableDeviceForCurrentUser();
}

@Override
public void registerForPush() {
moduleImpl.registerForPush();
}

@Override
public void handleAppLink(String uri, Promise promise) {
moduleImpl.handleAppLink(uri, promise);
Expand Down
5 changes: 5 additions & 0 deletions android/src/oldarch/java/com/RNIterableAPIModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ public void disableDeviceForCurrentUser() {
moduleImpl.disableDeviceForCurrentUser();
}

@ReactMethod
public void registerForPush() {
moduleImpl.registerForPush();
}

@ReactMethod
public void handleAppLink(String uri, Promise promise) {
moduleImpl.handleAppLink(uri, promise);
Expand Down
8 changes: 8 additions & 0 deletions ios/RNIterableAPI/RNIterableAPI.mm
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ - (void)disableDeviceForCurrentUser {
[_swiftAPI disableDeviceForCurrentUser];
}

- (void)registerForPush {
[_swiftAPI registerForPush];
}

- (void)getLastPushPayload:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject {
[_swiftAPI getLastPushPayload:resolve rejecter:reject];
Expand Down Expand Up @@ -512,6 +516,10 @@ - (void)wakeApp {
[_swiftAPI disableDeviceForCurrentUser];
}

RCT_EXPORT_METHOD(registerForPush) {
[_swiftAPI registerForPush];
}

RCT_EXPORT_METHOD(getLastPushPayload : (RCTPromiseResolveBlock)
resolve reject : (RCTPromiseRejectBlock)reject) {
[_swiftAPI getLastPushPayload:resolve rejecter:reject];
Expand Down
8 changes: 8 additions & 0 deletions ios/RNIterableAPI/ReactIterableAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ import React
IterableAPI.disableDeviceForCurrentUser()
}

@objc(registerForPush)
public func registerForPush() {
ITBInfo()
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}

@objc(getLastPushPayload:rejecter:)
public func getLastPushPayload(resolver: RCTPromiseResolveBlock, rejecter: RCTPromiseRejectBlock)
{
Expand Down
2 changes: 2 additions & 0 deletions src/__mocks__/MockRNIterableAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export class MockRNIterableAPI {

static disableDeviceForCurrentUser = jest.fn();

static registerForPush = jest.fn();

static trackPushOpenWithCampaignId = jest.fn();

static updateCart = jest.fn();
Expand Down
1 change: 1 addition & 0 deletions src/api/NativeRNIterableAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export interface Spec extends TurboModule {

// Device management
disableDeviceForCurrentUser(): void;
registerForPush(): void;
getLastPushPayload(): Promise<{
[key: string]: string | number | boolean;
} | null>;
Expand Down
10 changes: 10 additions & 0 deletions src/core/classes/Iterable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ describe('Iterable', () => {
});
});

describe('registerForPush', () => {
it('should re-register the device for push notifications', () => {
// GIVEN no parameters
// WHEN Iterable.registerForPush is called
Iterable.registerForPush();
// THEN corresponding method is called on RNIterableAPI
expect(MockRNIterableAPI.registerForPush).toBeCalled();
});
});

describe('getLastPushPayload', () => {
it('should return the last push payload', async () => {
const result = { var1: 'val1', var2: true };
Expand Down
20 changes: 20 additions & 0 deletions src/core/classes/Iterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,26 @@ export class Iterable {
IterableApi.disableDeviceForCurrentUser();
}

/**
* Re-register the device for push notifications for the current user.
*
* This method can be used to re-enable push notifications after they have been
* disabled by calling `disableDeviceForCurrentUser`. It triggers the native
* push registration flow, re-registering the device token with Iterable.
*
* @example
* ```typescript
* // First disable push
* Iterable.disableDeviceForCurrentUser();
*
* // Later, re-enable push
* Iterable.registerForPush();
* ```
*/
static registerForPush() {
IterableApi.registerForPush();
}

/**
* Get the payload of the last push notification with which the user
* opened the application (by clicking an action button, etc.).
Expand Down
11 changes: 11 additions & 0 deletions src/core/classes/IterableApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,17 @@ describe('IterableApi', () => {
});
});

describe('registerForPush', () => {
it('should call RNIterableAPI.registerForPush', () => {
// GIVEN no parameters
// WHEN registerForPush is called
IterableApi.registerForPush();

// THEN RNIterableAPI.registerForPush is called
expect(MockRNIterableAPI.registerForPush).toBeCalled();
});
});

describe('updateUser', () => {
it('should call RNIterableAPI.updateUser with data fields and merge flag', () => {
// GIVEN data fields and merge flag
Expand Down
9 changes: 9 additions & 0 deletions src/core/classes/IterableApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ export class IterableApi {
return RNIterableAPI.disableDeviceForCurrentUser();
}

/**
* Re-register the device for push notifications for the current user.
* This can be used to re-enable push notifications after calling disableDeviceForCurrentUser.
*/
static registerForPush() {
IterableLogger.log('registerForPush');
return RNIterableAPI.registerForPush();
}

/**
* Save data to the current user's Iterable profile.
*
Expand Down
Loading