Allows for the integration of PushWoosh notifications in Titanium applications.
- Titanium SDK 12.7.0+
iOS - here
Android - here
API_TOKEN - here
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>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]" />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>NOTE: Your aps-environment must match you PushWoosh gateway when setting the p.8 key. Doc here.
- Add the following require
require('ti.pushwoosh');
Register device for Push Notifications
constpushwoosh=require('ti.pushwoosh');
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);}}});
Registers current device for push notifications.
PushWoosh.registerForPushNotifications();You can set specific tags for the device.
pushwoosh.setTags({"name": "John","age": 35,"logged_in": false,"ids": ["123abc","456def","789ghi"]})pushwoosh.getTagValue("name",(pw)=>{Ti.API.info(pw);});Check if the app opened from a notification click, and if so, fires the ON_MESSAGE_OPENED event.
PushWoosh.processPendingPushMessage();| Types | Description |
|---|---|
| ON_REGISTER_SUCCESS | Device registered successfully. You can get notifications now. |
| ON_REGISTER_ERROR | Device was not registered. |
| ON_MESSAGE_RECEIVED | When a push notification arrives. Works only in foreground. |
| ON_MESSAGE_OPENED | When the user clicks on notification. |
| ON_SET_TAG_SUCCESS | When the tag is saved successfully. |
| ON_SET_TAG_ERROR | Not possible to save the tag. |