Plugin API Reference

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

Functions

Functions

init(config, success, fail)

[android, ios]
Initializes Pushwoosh module with application ID and Google project number.

register(success, fail)

[android, ios]
Registers current device to receive push notifications.

unregister(success, fail)

[android, ios]
Unregisters current deivce from receiving push notifications.

setTags(tags, success, fail)

[android, ios]
Sets tags associated with current device and application.

getTags(success, fail)

[android, ios]
Gets tags associated with current device and application.

getPushToken(success)

[android, ios]
Returns push token or null if device is not registered to receive push notifications.

getHwid(success)

[android, ios]
Returns Pushwoosh HWID used for communications with Pushwoosh API.

setUserId(userId)

[android, ios]
Sets User Indentifier – a Facebook ID, username, email, or any other user ID. This allows data and events to be matched across multiple user devices.

postEvent(event, attributes)

[android, ios]
Posts events for In-App Messages. This can trigger In-App message displayed as specified in Pushwoosh Control Panel.

[android, ios]
Starts geolocation-based push notifications. Geozones are configured in Pushwoosh Control panel.

[android, ios]
Stops geolocation-based push notifications.

[android, ios]
Set application icon badge number.

[android, ios]
Returns application icon badge number.

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

[android]
Allows multiple notifications to be displayed in the Android Notification Center.

[android]
Turns screen on if notification arrives.

[android]
Enables LED blinking when notification arrives and display is off.

setColorLED(color)

[android]
Set LED color. Use with <setEnableLED>.

[android]
Sets default sound for incoming push notifications.

[android]
Sets default vibration mode for incoming push notifications.

Events

Event

Push notification opened event.

Push notification received event.

init

init(config: Object, success: ?Function, fail: ?Function)

[android, ios]
Initializes Pushwoosh module with application ID and Google project number.

Parameter
Description

config

Pushwoosh initialization config

config.pw_appid

Pushwoosh application ID

config.project_number

GCM project number (for Android push notifications)

success

(optional) initialization success callback

fail

(optional) initialization failure callback

register

register(success: ?Function, fail: ?Function)

[android, ios]
Registers current device to receive push notifications.

Parameter
Description

success

(optional) registration success callback. Receives push token as parameter

fail

(optional) registration failure callback

NOTE: if the user does not allow the 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: ?Function, fail: ?Function)

[android, ios]
Unregisters current deivce from receiving push notifications.

Parameter
Description

success

(optional) deregistration success callback

fail

(optional) deregistration failure callback

setTags

setTags(tags: Object, success: ?Function, fail: ?Function)

[android, ios]
Sets tags associated with current device and application.

Parameter
Description

tags

Tags associated with current device

success

(optional) method success callback

fail

(optional) method failure callback

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

getTags

getTags(success: Function, fail: ?Function)

[android, ios]
Gets tags associated with current device and application.

Parameter
Description

success

(optional) method success callback. Receives object containing tags as parameter

fail

(optional) method failure callback

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: Function)

[android, ios]
Returns push token or null if device is not registered to receive push notifications.

Parameter
Description

success

Method success callback. Receives push token as a parameter

getHwid

getHwid(success: Function)

[android, ios]
Returns Pushwoosh HWID used for communications with Pushwoosh API.

Parameter
Description

success

Method success callback. Receives Pushwoosh HWID as a parameter

setUserId

setUserId(userId: string)

[android, ios]
Sets User Indentifier – a Facebook ID, username, email, or any other user ID. This allows data and events to be matched across multiple user devices.

Parameter
Description

userId

Identifier of the currently logged user

postEvent

postEvent(event: string, attributes: ?Object)

[android, ios]
Posts events for In-App Messages. This triggers displaying of In-App message as specified in Pushwoosh Control Panel.

Parameter
Description

event

Event name

attributes

Additional event data

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

startLocationTracking

startLocationTracking()

[android, ios]
Starts geolocation-based push notifications. Geozones are configured in Pushwoosh Control panel.
Requires geolocation permissions http://docs.pushwoosh.com/docs/androidmanifestxml-modifications#geozones-push-notifications, http://docs.pushwoosh.com/docs/customizing-ios-sdk#geozones-push-notifications.

stopLocationTracking

stopLocationTracking()

[android, ios]
Stops geolocation-based push notifications.

setApplicationIconBadgeNumber

setApplicationIconBadgeNumber(badgeNumber: number)

[android, ios]
Set application icon badge number. Requires badge permissions http://docs.pushwoosh.com/docs/androidmanifestxml-modifications#using-badge-number-on-android.

Parameter
Description

badgeNumber

Icon badge number

getApplicationIconBadgeNumber

getApplicationIconBadgeNumber(callback: Function)

[android, ios]
Returns application icon badge number.

Parameter
Description

callback

Success callback

addToApplicationIconBadgeNumber

addToApplicationIconBadgeNumber(badgeNumber: number)

[android, ios]
Adds value to application icon badge. Requires badge permissions http://docs.pushwoosh.com/docs/androidmanifestxml-modifications#using-badge-number-on-android.

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)

pushReceived

[android, ios]
Push notification received event is fired when push is received in app.

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

pushOpened

[android, ios]
Push notification opened event is fired when user clicks on push notification.

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

Plugin API Reference