Skip to content

Instantly share code, notes, and snippets.

@jehartzog
Last active October 5, 2020 23:22
Show Gist options
  • Save jehartzog/9490e310a07d74a546c680a27c4a339a to your computer and use it in GitHub Desktop.
Save jehartzog/9490e310a07d74a546c680a27c4a339a to your computer and use it in GitHub Desktop.
Iterable Android Notification Action not fired at App Load Workaround
const getIterableInternalData = (payload: IterablePushPayload): any =>
Platform.OS === 'android'
? JSON.parse((payload as IterablePushPayloadAndroid).itbl)
: (payload as IterablePushPayloadIOS).itbl;
const doAndroidAppLoadCheck = async () => {
if (Platform.OS !== 'android') {
return;
}
const payload = (await Iterable.getLastPushPayload()) as IterablePushPayloadAndroid;
if (!payload) {
return;
}
const {actionIdentifier} = payload;
const itbl = getIterableInternalData(payload);
if (actionIdentifier === 'default') {
// The Iterable urlHandler and 'openApp' fires as expected, so we can ignore those
// We still process 'openApp' as that's what the iOS one does and we want to be consistent w/ lib
const {defaultAction} = itbl;
if (['openUrl'].includes(defaultAction?.type)) {
return;
}
// We set an action to be the default, so let's handle it
await iterableCustomActionHandler(defaultAction, {} as any);
return;
}
// We pressed a notification action button, so we need to figure out which one and fire the action
const {actionButtons} = itbl;
const actionButton = actionButtons.find(
(actionButtonOption: any) => actionButtonOption.identifier === actionIdentifier
);
if (!actionButton) {
return;
}
const {action} = actionButton;
await iterableCustomActionHandler(action, {} as any);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment