Last active
October 5, 2020 23:22
-
-
Save jehartzog/9490e310a07d74a546c680a27c4a339a to your computer and use it in GitHub Desktop.
Iterable Android Notification Action not fired at App Load Workaround
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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