Menu

Mobify Push

The Push plugin allows the integration with Mobify Push Notifications. The app can subscribe to receive messages sent through Mobify Push. Received messages will be displayed as system notifications.

In iOS, the system shows a mandatory dialog to ask the user's permission to allow push notifications from the app. This document refers to the mandatory dialog as the hard ask dialog.

Sample Usage

const pushPlugin = await PushPlugin.init('mobify_site_id_name', engagementControllerPromise)
pushPlugin.subscribe();

Methods

PushPlugin.init(siteId, engagementControllerPromise) #

Creates and returns an instance of the Push plugin that is used to make subsequent method calls. It will also register itself as a deepLinkHandler on Application and will intercept any deeplink satisfying https://deeplink.mobify.net/<site_id>/register_test_push.


getSubscriptionStatus() #

Returns the current subscription status of the user.

The returned object has the following fields:


setNotificationIconPath(path) - (Android only) #

Sets the image to be displayed as the notification icon.


subscribe() #

Subscribe device to receive push notification. iOS will display a hard-ask dialog. If user accepts the dialog then push notifications will be enabled on the device.

(Android only) setNotificationIconPath must be called before subscribe can be called.


subscribeTest() #

Subscribes the app to receive test push notifications from Mobify Push. (Android only) setNotificationIconPath must be called before subscribeTest can be called. Called automatically if Application receives a matching deeplink (see init).


messageClickedWhenAppIsOpen(options) - (iOS only) #

Opens url as a deep link and sends notification to the Mobify Engagement Engine when a message which has been received while the app is open is clicked on. This function be called manually in iOS for messages received when the app is open. In all other cases Astro will internally handle this behavior.


setLocale(locale) #

Set the current locale to inform the push backend which language to use when sending messages to this user. This will be set to the current locale of the device, but you can use setLocale to change it to something else. (if your app offers language customization, for example)


setOptedOut(optedOut) #

Set the current opt-out state of the user's push subscription. The default is false, and if set to true, the user will no longer receive push notifications.

Events

systemAllowed → {clientId} #

In iOS, fires when the hard ask dialog is accepted by the user. In Android, fires when plugin confirms that Google Play services is enabled.


systemBlocked → {clientId} #

In iOS, fires when the hard ask dialog is denied by the user. In Android, fires when plugin confirms that Google Play services in not enabled.


messageReceivedWhenAppIsOpen → {clientId, title, message, url} (iOS Only) #

Fires when push notification is received while the app is running.


messageClicked → {clientId, title, message, url} #

Fires when push notification is clicked by the user.


subscribeTestTriggered → {} #

Fires when Application receives a matching deeplink (see init), after subscribeTest is called. This is where you can display some UI to inform the user that test mode has been triggered.

Note: It can take up to a minute for the backend to be fully updated with this change, and it requires internet access to succeed. It is advised to inform the user about these details in the UI.