Back

titanium 插件: 推送(push via urban air ship)

发布时间: 2015-01-11 02:00:00

refer to:  https://github.com/FokkeZB/UTiL/tree/master/urbanairport 
https://marketplace.appcelerator.com/apps/4984#!overview (module的下载地址), 以及:
http://fokkezb.nl/2013/10/14/setting-up-urban-airship/ (详细用法)

var urbanairport = require('urbanairport');

urbanairport.register({
  debug: true, // Show debug info

  // Sets push types
  sound: true,   // iOS + Android (default)
  vibrate: true, // Android (default)
  badge: true,   // iOS (default)
  alert: true,   // iOS (default)

  // Use any native property or single-property method of the modules
  showOnAppClick: true,

  // Enable compatibility-mode (see blog)
  compatibility: true,

  // On Android these will be automatically set once UA is flying
  alias: 'John',
  tags: 'single', // Supports both a single or Array of strings!

  callback: function(e) { // The only callback you need

    // Registration failed
    if (e.type === 'error') {
      alert('Sorry, no push for you: ' + e.error);

    // Registration done
    } else if (e.type === 'success') {
      alert('Your token is: ' + e.deviceToken);

    // Received notification
    } else if (e.type === 'callback') {

      // Properties are normalized for iOS and Android:
      // e.payload === e.data === e.data.aps
      // e.message === e.data.alert === e.data.aps.alert
      alert(e.message);
    }
  }
});

// Manually disable/re-enable push
urbanairport.disable(); // enable();

// Append tags instead of resetting them
urbanairport.addTags('foo'); // Both single and Array supported

// Remove one or more tags
urbanairport.removeTags(['foo','bar']); // Both single and Array supported

Back