Skip to content

Latest commit

 

History

History
515 lines (394 loc) · 14.2 KB

README.md

File metadata and controls

515 lines (394 loc) · 14.2 KB

Pushwoosh React Native Module

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));
});

Summary


Functions
init(config, success, fail)
register(success, fail)
unregister(success, fail)
setTags(tags, success, fail)
getTags(success, fail)
getPushToken(success)
getHwid(success)
setUserId(userId, success, fail)
postEvent(event, attributes)
setApplicationIconBadgeNumber(badgeNumber)
getApplicationIconBadgeNumber(callback)
addToApplicationIconBadgeNumber(badgeNumber)
setMultiNotificationMode(on)
setLightScreenOnNotification(on)
setEnableLED(on)
setColorLED(color)
setSoundType(type)
setVibrateType(type)
presentInboxUI()
showGDPRConsentUI()
showGDPRDeletionUI()
setCommunicationEnabled()
removeAllDeviceData()
enableHuaweiPushNotifications()
Events
pushOpened
pushReceived

init

init(config, success, fail)

Initializes Pushwoosh module with application id and google project number.

Parameters
objectconfigPushwoosh initialization config.
stringconfig.pw_appidPushwoosh application id.
stringconfig.project_numberGCM project number (for Android push notifications).
stringconfig.reverse_proxy_url(optional) Url to your reverse proxy.
stringconfig.pw_notification_handling(optional) To use custom notification handling on iOS specify the parameter "pw_notification_handling" to "CUSTOM".
functionsuccess(optional) initialization success callback.
functionfail(optional) initialization failure callback.

register

register(success, fail)

Registers current device for push notifications.

Parameters
functionsuccess(optional) registration success callback. Receives push token as parameter.
functionfail(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

unregister(success, fail)

Unregisters current deivce from receiving push notifications.

Parameters
functionsuccess(optional) deregistration success callback.
functionfail(optional) deregistration failure callback.

setTags

setTags(tags, success, fail)

Set tags associated with current device and application.

Parameters
objecttagsTags associated with current device.
functionsuccess(optional) method success callback.
functionfail(optional) method failure callback.

Example:

pushNotification.setTags({ "string_tag" : "Hello world", "int_tag" : 42, "list_tag":["hello", "world"]});

getTags

getTags(success, fail)

Get tags associated with current device and application.

Parameters
functionsuccess(optional) method success callback. Receives object containing tags as parameter.
functionfail(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

getPushToken(success)

Returns push token or null if device is not registered for push notifications.

Parameters
functionsuccessMethod success callback. Receives push token as parameter.

getHwid

getHwid(success)

Returns Pushwoosh HWID used for communications with Pushwoosh API.

Parameters
functionsuccessMethod success callback. Receives Pushwoosh HWID as parameter.

setUserId

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
stringuserIdIdentifier of currently logged in user
functionsuccess(optional) method success callback.
functionfail(optional) method failure callback.

postEvent

postEvent(event, attributes)

Post events for In-App Messages. This can trigger In-App message display as specified in Pushwoosh Control Panel.

Parameters
stringeventEvent name.
objectattributesAdditional event data.

Example:

Pushwoosh.postEvent("buttonPressed", { "buttonNumber" : "4", "buttonLabel" : "Banner" })

setApplicationIconBadgeNumber

setApplicationIconBadgeNumber(badgeNumber)

[android, ios]
Set application icon badge number.

Parameter Description
badgeNumber Icon badge number

getApplicationIconBadgeNumber

getApplicationIconBadgeNumber(callback: Function)

[android, ios]
Returns application icon badge number.

addToApplicationIconBadgeNumber

addToApplicationIconBadgeNumber(badgeNumber: number)

[android, ios]
Adds value to application icon badge.

Parameter Description
badgeNumber Incremental icon badge number

setMultiNotificationMode

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

setLightScreenOnNotification(on: boolean)

[android]
Turns screen on when notification arrives.

Parameter Description
on Enable/disable screen unlock (is disabled by default)

setEnableLED

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

setColorLED(color: number)

[android]
Set led color. Use with setEnableLED.

Parameter Description
color LED color in ARGB integer format

setSoundType

setSoundType(type: number)

[android]
Sets default sound for incoming push notifications.

Parameter Description
type Sound type (0 – default, 1 – no sound, 2 – always)

setVibrateType

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

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

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

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

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

removeAllDeviceData()

[android, ios]
Removes all data about the device. Cannot be undone.

enableHuaweiPushNotifications

enableHuaweiPushNotifications()

[android]
Enables Huawei push messaging. Requires configured Huawei platform for your Pushwoosh application. See the integration guide.

pushReceived

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.

pushOpened

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.