Provides module for React Native to receive and handle push notifications for iOS and Android.
Example:
var Pushwoosh = require('pushwoosh-react-native-plugin');
Pushwoosh.init({ "pw_appid" : "PUSHWOOSH_APP_ID" , "project_number" : "GOOGLE_PROJECT_NUMBER" });
Pushwoosh.register(
(token) => {
console.warn("Registered for push notifications with token: " + token);
},
(error) => {
console.warn("Failed to register for push notifications: " + error);
}
);
// this event is fired when the push is received in the app
DeviceEventEmitter.addListener('pushReceived', (e: Event) => {
console.warn("pushReceived: " + JSON.stringify(e));
});
// this event is fired when user clicks on notification
DeviceEventEmitter.addListener('pushOpened', (e: Event) => {
console.warn("pushOpened: " + JSON.stringify(e));
});
init(config, success, fail)
Initializes Pushwoosh module with application id and google project number.
Parameters | ||
---|---|---|
object | config | Pushwoosh initialization config. |
string | config.pw_appid | Pushwoosh application id. |
string | config.project_number | GCM project number (for Android push notifications). |
string | config.reverse_proxy_url | (optional) Url to your reverse proxy. |
string | config.pw_notification_handling | (optional) To use custom notification handling on iOS specify the parameter "pw_notification_handling" to "CUSTOM". |
function | success | (optional) initialization success callback. |
function | fail | (optional) initialization failure callback. |
register(success, fail)
Registers current device for push notifications.
Parameters | ||
---|---|---|
function | success | (optional) registration success callback. Receives push token as parameter. |
function | fail | (optional) registration failure callback. |
NOTE: if user does not allow application to receive push notifications and UIBackgroundModes remote-notificaion
is not set in Info.plist none of these callbacks will be called.
unregister(success, fail)
Unregisters current deivce from receiving push notifications.
Parameters | ||
---|---|---|
function | success | (optional) deregistration success callback. |
function | fail | (optional) deregistration failure callback. |
setTags(tags, success, fail)
Set tags associated with current device and application.
Parameters | ||
---|---|---|
object | tags | Tags associated with current device. |
function | success | (optional) method success callback. |
function | fail | (optional) method failure callback. |
Example:
pushNotification.setTags({ "string_tag" : "Hello world", "int_tag" : 42, "list_tag":["hello", "world"]});
getTags(success, fail)
Get tags associated with current device and application.
Parameters | ||
---|---|---|
function | success | (optional) method success callback. Receives object containing tags as parameter. |
function | fail | (optional) method failure callback. |
Example:
Pushwoosh.getTags(
function(tags)
{
console.warn('tags for the device: ' + JSON.stringify(tags));
},
function(error)
{
console.warn('get tags error: ' + JSON.stringify(error));
}
);
getPushToken(success)
Returns push token or null if device is not registered for push notifications.
Parameters | ||
---|---|---|
function | success | Method success callback. Receives push token as parameter. |
getHwid(success)
Returns Pushwoosh HWID used for communications with Pushwoosh API.
Parameters | ||
---|---|---|
function | success | Method success callback. Receives Pushwoosh HWID as parameter. |
setUserId(userId, success, fail)
Set User indentifier. This could be Facebook ID, username or email, or any other user ID. This allows data and events to be matched across multiple user devices.
Parameters | ||
---|---|---|
string | userId | Identifier of currently logged in user |
function | success | (optional) method success callback. |
function | fail | (optional) method failure callback. |
postEvent(event, attributes)
Post events for In-App Messages. This can trigger In-App message display as specified in Pushwoosh Control Panel.
Parameters | ||
---|---|---|
string | event | Event name. |
object | attributes | Additional event data. |
Example:
Pushwoosh.postEvent("buttonPressed", { "buttonNumber" : "4", "buttonLabel" : "Banner" })
setApplicationIconBadgeNumber(badgeNumber)
[android, ios]
Set application icon badge number.
Parameter | Description |
---|---|
badgeNumber | Icon badge number |
getApplicationIconBadgeNumber(callback: Function)
[android, ios]
Returns application icon badge number.
addToApplicationIconBadgeNumber(badgeNumber: number)
[android, ios]
Adds value to application icon badge.
Parameter | Description |
---|---|
badgeNumber | Incremental icon badge number |
setMultiNotificationMode(on: boolean)
[android]
Allows multiple notifications to be displayed in the Android Notification Center.
Parameter | Description |
---|---|
on | Enable/disable multiple notifications (is disabled by default) |
setLightScreenOnNotification(on: boolean)
[android]
Turns screen on when notification arrives.
Parameter | Description |
---|---|
on | Enable/disable screen unlock (is disabled by default) |
setEnableLED(on: boolean)
[android]
Enables LED blinking when notification arrives and display is off.
Parameter | Description |
---|---|
on | Enable/disable LED blink (disabled by default) |
setColorLED(color: number)
[android]
Set led color. Use with setEnableLED.
Parameter | Description |
---|---|
color | LED color in ARGB integer format |
setSoundType(type: number)
[android]
Sets default sound for incoming push notifications.
Parameter | Description |
---|---|
type | Sound type (0 – default, 1 – no sound, 2 – always) |
setVibrateType(type: number)
[android]
Sets default vibration mode for incoming push notifications.
Parameter | Description |
---|---|
type | Vibration type (0 – default, 1 – no vibration, 2 – always) |
presentInboxUI()
Opens Inbox screen.
Before using Message Inbox, please add node_modules/pushwoosh-react-native-plugin/src/ios/PushwooshInboxBundle.bundle to your project. Or, launch a script 'node node_modules/pushwoosh-react-native-plugin/scripts/add_inbox_ios_resources.js' to do it.
showGDPRConsentUI()
[android, ios]
A part of The GDPR Compliance solution that shows the GDPR Consent Form, ensuring lawful basis for processing personal data of EU citizens.
showGDPRDeletionUI()
[android, ios]
A part of The GDPR Compliance solution that shows the GDPR Deletion Form, ensuring means to comply with the right to erasure.
setCommunicationEnabled(on: boolean)
[android, ios]
A binary method enabling/disabling all communication with Pushwoosh. The boolean value is false unsubscribes the device from receiving push notifications and stops in-app messages download. The value true reverses the effect.
removeAllDeviceData()
[android, ios]
Removes all data about the device. Cannot be undone.
enableHuaweiPushNotifications()
[android]
Enables Huawei push messaging. Requires configured Huawei platform for your Pushwoosh application. See the integration guide.
DeviceEventEmitter.addListener('pushReceived', (e: Event) => {
console.warn("pushReceived: " + JSON.stringify(e));
// shows a push is received. Implement passive reaction to a push, such as UI update or data download.
});
[android, ios]
Push notification received event is fired when push is received in app.
DeviceEventEmitter.addListener('pushOpened', (e: Event) => {
console.warn("pushOpened: " + JSON.stringify(e));
// shows a user tapped the notification. Implement user interaction, such as showing push details.
});
[android, ios]
Push notification opened event is fired when user clicks on push notification.