»  IOS »  Native iOS SDK »   Appcelerator Titanium

Appcelerator Titanium

Appcelerator titanium has never been so easy! Our extensive guides for all platforms currently available on the market show how to integrate push notifications within several minutes and with several lines of code. You can choose between native programming tools and a diverse set of cross-platform solutions. We are working hard on extending the list of supported SDKs, plugins and modules, so we advise coming back once in a while to see what's new. If you believe that some great tools should be added here, please let us know, and we will do our best to get them up and running!

 

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.

 

var BlukPush = require('BlukPush/BlukPush');
BlukPush.appCode = ‘YOUR_APP_CODE’;

 

3. Registering and handling BlukPush notifications. On start of the application call the following function:

 

 vardeviceToken = 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:

 

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

 

Stats


Call this function on start to track application open stat

 

//record stats for app open with BlukPush
BlukPush.sendAppOpen();

 

Call this function in your push notifications handler to track opened push notifications count:

 

//send stats to BlukPush about push opened
BlukPush.sendPushStat(e.data.p);

© 2015 BulkPush.com By Broadnet Technologies Ltd.