Skip to content

Latest commit

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Ti.PushWoosh platforms

Allows for the integration of PushWoosh notifications in Titanium applications.

Requirements

  • Titanium SDK 12.7.0+

PushWoosh Integration

iOS - here

Android - here

API_TOKEN - here

Setup

Integrate the module into the modules folder and define them into the tiapp.xml file:

 <modules>
<moduleplatform="iphone">ti.pushwoosh</module>
<moduleplatform="android">ti.pushwoosh</module>
</modules>

Android

To use PushWoosh on Android devices, register some meta-data in the Application node of you Android manifest in Tiapp.xml :

	<meta-dataandroid:name="com.pushwoosh.appid"android:value="[APP-ID]"/>
<meta-dataandroid:name="com.pushwoosh.senderid"android:value="[FCM-SENDER-ID]"/>
<meta-dataandroid:name="com.pushwoosh.apitoken"android:value="[API-KEY]" />

PushWoosh Android DOC

iOS

To use PushWoosh on iOS devices, register some meta-data in the plist node in Tiapp.xml :

<ios>
<plist>
<dict>
<key>aps-environment</key>
<string>production</string> <!-- or development -->
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
<string>fetch</string>
</array>
<!--PushWoosh-->
<key>Pushwoosh_APPID</key>
<string>[APP-ID]</string>
<key>Pushwoosh_API_TOKEN</key>
<string>[API-KEY]</string>
<key>PW_APP_GROUPS_NAME</key>
<string>group.ti.pushwoosh</string>
</dict>
</plist>
</ios>

Also, you need to create/edit Entitlements.plist in the root of your project, alongside Tiapp.xml, with the following fields:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPEplist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plistversion="1.0">
<dict>
<key>aps-environment</key>
<string>production</string> <!-- or development --><!--PushWoosh-->
<key>com.apple.security.application-groups</key>
<array>
<string>group.ti.pushwoosh</string>
</array>
</dict>
</plist>

PushWoosh iOS DOC

NOTE: Your aps-environment must match you PushWoosh gateway when setting the p.8 key. Doc here.

Usage

In your app.js

  1. Add the following require
    require('ti.pushwoosh');

Push Notification

  1. Register device for Push Notifications

    constpushwoosh=require('ti.pushwoosh');
  2. You can request permission to use notifications:

    mainWindow.addEventListener('open',()=>{if(Ti.Platform.osname!="android"){// iOS onlyPushWoosh.processPendingPushMessage();// Check if the app opened from a notification click.}PushWoosh.registerForPushNotifications();}PushWoosh.addEventListener(PushWoosh.ON_REGISTER_SUCCESS,(pw)=>{Ti.API.warn("PushWoosh.ON_REGISTER_SUCCESS!");Ti.API.info("Token: "+pw.token);});PushWoosh.addEventListener(PushWoosh.ON_REGISTER_ERROR,(pw)=>{Ti.API.error("PushWoosh.ON_REGISTER_ERROR!");Ti.API.error(pw);});PushWoosh.addEventListener(PushWoosh.ON_MESSAGE_RECEIVED,(pw)=>{Ti.API.warn("PushWoosh.ON_MESSAGE_RECEIVED");Ti.API.info(pw);});PushWoosh.addEventListener(PushWoosh.ON_MESSAGE_OPENED,(pw)=>{Ti.API.warn("PushWoosh.ON_MESSAGE_OPENED");if(Ti.Platform.osname=="android"){if(pw?.message?.customData){constcustomData=JSON.parse(pw.message.customData);}}else{// iOSif(pw?.payload?.u){constcustomData=JSON.parse(pw.payload.u);}}});

Methods

registerForPushNotifications()

Registers current device for push notifications.

PushWoosh.registerForPushNotifications();

setTags

You can set specific tags for the device.

pushwoosh.setTags({"name": "John","age": 35,"logged_in": false,"ids": ["123abc","456def","789ghi"]})

getTagValue

pushwoosh.getTagValue("name",(pw)=>{Ti.API.info(pw);});

processPendingPushMessage ( iOS only )

Check if the app opened from a notification click, and if so, fires the ON_MESSAGE_OPENED event.

PushWoosh.processPendingPushMessage();

Events

TypesDescription
ON_REGISTER_SUCCESSDevice registered successfully. You can get notifications now.
ON_REGISTER_ERRORDevice was not registered.
ON_MESSAGE_RECEIVEDWhen a push notification arrives. Works only in foreground.
ON_MESSAGE_OPENEDWhen the user clicks on notification.
ON_SET_TAG_SUCCESSWhen the tag is saved successfully.
ON_SET_TAG_ERRORNot possible to save the tag.

About

No description or website provided.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages