Git Product home page Git Product logo

tipushnotification's Introduction

TiPushNotification

Yes you can use it with your self-hosted server or any other cloud services like Parse.com or Appcelerator cloud.

Get it gitTio

Download the latest distribution ZIP-file with latest Android GCM module and consult the Titanium Documentation on how install it, or simply use the gitTio CLI:

$ gittio install ti-push-notification

How to

Titanium has APIs for iOS push notifications, but unfortunately you need module to for Android.

  1. Install this CommonJS module

Note: Android GCM module will be installed automaticly

$ gittio install ti-push-notification

  1. Add this code into your app.js or alloy.js
if (Ti.Platform.name === 'android') {
  // set android-only options
  var pnOptions = {
    senderId: 'XXXXXXXX', // It's the same as your project id
    notificationSettings: {
      sound: 'mysound.mp3', // Place soudn file in platform/android/res/raw/mysound.mp3
      smallIcon: 'appicon.png', // Place icon in platform/android/res/drawable/notification_icon.png
      largeIcon: 'appicon.png', // Same
      vibrate: true, // Whether the phone should vibrate
      insistent: true, // Whether the notification should be insistent
      group: 'News', // Name of group to group similar notifications together
      localOnly: false, // Whether this notification should be bridged to other devices
      priority: 2 // Notification priority, from -2 to 2
    }
  };

} else if (Ti.Platform.name === 'iPhone OS') { // set ios-only options.
  // Sets interactive notifications as well if iOS8 and above. Interactive notifications is optional.
  if (parseInt(Ti.Platform.version.split(".")[0], 10) >= 8) {
    var thumbUpAction = Ti.App.iOS.createUserNotificationAction({
      identifier: "THUMBUP_IDENTIFIER",
      title: "Agree",
      activationMode: Ti.App.iOS.USER_NOTIFICATION_ACTIVATION_MODE_BACKGROUND,
      destructive: false,
      authenticationRequired: false
    });

    var thumbDownAction = Ti.App.iOS.createUserNotificationAction({
      identifier: "THUMBDOWN_IDENTIFIER",
      title: "Disagree",
      activationMode: Ti.App.iOS.USER_NOTIFICATION_ACTIVATION_MODE_BACKGROUND,
      destructive: false,
      authenticationRequired: false
    });

    var thumbUpDownCategory = Ti.App.iOS.createUserNotificationCategory({
      identifier: "THUMBUPDOWN_CATEGORY",
      // The following actions will be displayed for an alert dialog
      actionsForDefaultContext: [thumbUpAction, thumbDownAction],
      // The following actions will be displayed for all other notifications
      actionsForMinimalContext: [thumbUpAction, thumbDownAction]
    });

    var pnOptions = {
      types: [Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT, Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND],
      categories: [thumbUpDownCategory]
    };
  } else { //No support for interactive notifications, omit categories
    var pnOptions = {
      types: [Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT, Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND]
    };
  }
}

// set cross-platform event
var onReceive = function(event) {
  // Your code here
};

// Create instance with base url
var tiPush = require('ti-push-notification').init({
  backendUrl: "http://domain.tld/register.php"
});

// register this device
tiPush.registerDevice({
  pnOptions: pnOptions,
  onReceive: onReceive,
  extraOptions: {
    something: "a",
    key2: true,
    user_id: 1234,
    whatever: "youwant"
  }
});

Contributions

Your issues and pull requests are most welcome, also you can pick a task from TODOs.

TODOs

  1. Server-side snippets for PHP and NodeJS
  2. Parse.com example
  3. Wordpress self-hosted example
  4. APN Server API setup tutorial
  5. GCM Server API setup tutorial
  6. Add option to depend on CaffeinaLab GCM or Jeroen GCM module.

Changelog

v0.1.3
Add extraOptions parameter to be uploaded to backend too

v0.1.2
Implementation changed, no need for factory, use init function directly Now module Titaniumified

v0.1.0
Initialed base of ACS Push Notifications

Credits

This module is based on ACS Push Notifications CommonJS module by my Ricardo Alcocer.

License

Original code written in my full-time @ Rize Inno, code open source by Rize Innovations, FZO under MIT license.

tipushnotification's People

Contributors

douglashennrich avatar hazemkhaled avatar kaiiserni avatar m1ga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tipushnotification's Issues

Question about backend

Hi!

Every time the user open the app, it register the token on our backend server ? If so... there's a way to only register on backend once ?

Thanks =)

Open window when app start

Hi, I added settings code lines into alloy.js
When my app is not closed and working on background, onReceive function appear and my app opens new window with my custom codes that my defined into onReceive function.

But when I closed my app completely and click to received notification from Android notification area, my app opens but onReceive function doesn't appear and don't open new window.

Where is my fault? Any idea?

Gittio support

To be able to provide a Gittio package, you have to follow this naming convention for your release:
moduleid-platform-version.zip
While you release package right now is
TiPushNotification-0.1.0.zip

So, you need to rename the package to
TiPushNotification-commonjs-0.1.0.zip

and it will be automatically discovered by Gittio.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.