By Technical Support
#10 To integrate BlukPush into your Appcelerator Titanium iOS application you need to do simple following steps:
1. Download the sample and place the BlukPush.js script in your Resources folder (the folder where app.js is located): Generic Push Module Script
2. Include the following line in your app.js. Replace ‘YOUR_BLUKPUSH_APP_CODE’ with your BlukPush application code from the control panel.
Code: Select allvar BlukPush = require('BlukPush/BlukPush');
BlukPush.appCode = ‘YOUR_APP_CODE’;

3. Registering and handling BlukPush notifications. On start of the application call the following function:
Code: Select allvardeviceToken = null;
// Check if the device is running iOS 8 or later
   if(Ti.Platform.name ==
   "iPhone OS"&&parseInt(Ti.Platform.version.split(".")[0]) >= 8) {
      functionregisterForPush() {
       Ti.Network.registerForPushNotifications({
         success : deviceTokenSuccess,
         error : deviceTokenError,
         callback : receivePush
         });
// Remove event listener once registered for BlukPush
 
Ti.App.iOS.removeEventListener('usernotificationsettings',
registerForPush);
  };
     
// Wait for user settings to be registered before registering for BlukPush
   
Ti.App.iOS.addEventListener('usernotificationsettings',
registerForPush);
     
// Register notification types to use
   Ti.App.iOS.registerUserNotificationSettings({
   types : [Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT,
            Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND,
            Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE]
 });
    } else{
// For iOS 7 and earlier
   Ti.Network.registerForPushNotifications({
// Specifies which notifications to receive
   types : [Ti.Network.NOTIFICATION_TYPE_BADGE,
            Ti.Network.NOTIFICATION_TYPE_ALERT,
             Ti.Network.NOTIFICATION_TYPE_SOUND],
   success : deviceTokenSuccess,
   error : deviceTokenError,
   callback : receivePush
        });
    }
     
// Process incoming BlukPush notifications
     
  functionreceivePush(e) {
//alert('Received push: ' + JSON.stringify(e));
  Ti.API.warn("BlukPush message received: " + JSON.stringify(e));
             
     var a = Ti.UI.createAlertDialog({
     title : 'New Message',
     message : e.data.alert,
     buttonNames : [ 'Close']
//message :JSON.stringify(e.data) //if you want to access additional
                                  //custom data in the payload
    });
  a.show();
  a.addEventListener('click', function(e) {
  if (e.index == 0) {
 //Titanium.Platform.openURL(BlukPushURL);
   }
  });
   }     
 // Save the device token for subsequent API calls
    functiondeviceTokenSuccess(e) {
    deviceToken = e.deviceToken;
    Ti.API.info('successfully registered for
    apple device token with '+ e.deviceToken);
    BlukPush.register(deviceToken, function(data) {
    Ti.API.debug("BlukPush register success: "+ JSON.stringify(data));
    BlukPush.setTags({alias:"device1"}, function(data) {
    Ti.API.debug("BlukPushsendTags success: "+ JSON.stringify(data));
    },function(e) {
    Ti.API.warn("Couldn't setTags with BlukPush: "+ JSON.stringify(e));
    });       
      },
    function(e) {
    Ti.API.warn("Couldn't register with BlukPush: "+ JSON.stringify(e));
    });
    }
   
    functiondeviceTokenError(e) {
    alert('Failed to register for BlukPush notifications! '+ e.error);
    Ti.API.warn("BlukPushnotifications disabled: "+ JSON.stringify(e));
    }

4. Expert mode on!
Tags
Please note that the device has to be registered with BlukPushbefore calling this method:
Code: Select allBlukPush.setTags({alias:"device1"}, function(data) {
Ti.API.debug("BlukPushsendTags success: "+ JSON.stringify(data));
},function(e) {
Ti.API.warn("Couldn't setTags with BlukPush: "+ JSON.stringify(e));
});

Stats
Call this function on start to track application open stat
Code: Select all//record stats for app open with BlukPush
BlukPush.sendAppOpen();

Call this function in your push notifications handler to track opened push notifications count:
Code: Select all//send stats to BlukPush about push opened
BlukPush.sendPushStat(e.data.p);