Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,19 @@ public void onTokenRegistrationSuccessful(String authToken) {
sendEvent(EventName.handleAuthSuccessCalled.name(), null);
}

@Override
public void onTokenRegistrationFailed(String reason) {
IterableLogger.e(TAG, "Token registration failed: " + reason);
JSONObject reasonJson = new JSONObject();
try {
reasonJson.put("reason", reason != null ? reason : "unknown");
WritableMap eventData = Serialization.convertJsonToMap(reasonJson);
sendEvent(EventName.handleTokenRegistrationFailedCalled.name(), eventData);
} catch (JSONException e) {
IterableLogger.e(TAG, "Failed to send token registration failure event");
}
}

public void addListener(String eventName) {
// Keep: Required for RN built in Event Emitter Calls.
}
Expand Down Expand Up @@ -811,5 +824,6 @@ enum EventName {
handleInAppCalled,
handleUrlCalled,
receivedIterableEmbeddedMessagesChanged,
receivedIterableInboxChanged
receivedIterableInboxChanged,
handleTokenRegistrationFailedCalled
}
8 changes: 8 additions & 0 deletions ios/RNIterableAPI/ReactIterableAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import React
case handleAuthFailureCalled
case handleEmbeddedMessageUpdateCalled
case handleEmbeddedMessagingDisabledCalled
case handleTokenRegistrationFailedCalled
}

@objc public static var supportedEvents: [String] {
Expand Down Expand Up @@ -818,6 +819,13 @@ extension ReactIterableAPI: IterableAuthDelegate {
}

public func onTokenRegistrationFailed(_ reason: String?) {
ITBError("Token registration failed: \(reason ?? "unknown reason")")
guard shouldEmit else {
return
}
delegate?.sendEvent(
withName: EventName.handleTokenRegistrationFailedCalled.rawValue,
body: ["reason": reason ?? "unknown"] as [String: Any])
}
}

Expand Down
22 changes: 22 additions & 0 deletions src/core/classes/Iterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,9 @@ export class Iterable {
RNEventEmitter.removeAllListeners(
IterableEventName.handleEmbeddedMessagingDisabledCalled
);
RNEventEmitter.removeAllListeners(
IterableEventName.handleTokenRegistrationFailedCalled
);
}

/**
Expand Down Expand Up @@ -1109,6 +1112,25 @@ export class Iterable {
);
}
}

// Always listen for token registration failures so they are surfaced
// to developers. Without this, push registration errors (e.g. invalid
// pushIntegrationName) are silently swallowed.
RNEventEmitter.addListener(
IterableEventName.handleTokenRegistrationFailedCalled,
(dict: { reason: string }) => {
const reason = dict?.reason ?? 'unknown';

// Always log to console.error so developers can see the failure
// even without the callback configured
console.error(
`[Iterable] Push token registration failed: ${reason}. ` +
'Check that pushIntegrationName in your IterableConfig is valid.'
);

Iterable.savedConfig.onTokenRegistrationFailed?.(reason);
}
);
}

/**
Expand Down
22 changes: 22 additions & 0 deletions src/core/classes/IterableConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,28 @@ export class IterableConfig {
*/
onEmbeddedMessagingDisabled?: () => void;

/**
* A callback function that is called when push token registration fails.
*
* This can happen when `pushIntegrationName` is set to an invalid value,
* or when the `/api/users/registerDeviceToken` endpoint returns an error.
*
* Without this callback, push registration errors are silently ignored,
* making it difficult to diagnose push notification setup issues.
*
* @param reason - A string describing why token registration failed.
*
* @example
* ```typescript
* const config = new IterableConfig();
* config.onTokenRegistrationFailed = (reason) => {
* console.error('Push token registration failed:', reason);
* };
* Iterable.initialize('<YOUR_API_KEY>', config);
* ```
*/
onTokenRegistrationFailed?: (reason: string) => void;

/**
* Converts the IterableConfig instance to a dictionary object.
*
Expand Down
2 changes: 2 additions & 0 deletions src/core/enums/IterableEventName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ export enum IterableEventName {
handleEmbeddedMessageUpdateCalled = 'handleEmbeddedMessageUpdateCalled',
/** Event that fires when embedded messaging is disabled */
handleEmbeddedMessagingDisabledCalled = 'handleEmbeddedMessagingDisabledCalled',
/** Event that fires when push token registration fails (e.g., invalid pushIntegrationName) */
handleTokenRegistrationFailedCalled = 'handleTokenRegistrationFailedCalled',
}
Loading