Giter VIP home page Giter VIP logo

localnotify's Introduction

benCoding.localNotify Module

This module provides helper functions for creating Local Notifications within your Titanium iOS project. The localNotify is meant to replace the existing Titanium Schedule and Cancel methods.

Before you start

* You need Titanium 1.8.2 or greater.

Download the release

This module is freely available on github. Check the dist folder for a compiled release.

Building from source?

If you are building from source you will need to do the following:

  • Modify the titanium.xcconfig file with the path to your Titanium installation

Setup

  • Download the latest release from the dist folder or you can build it yourself.
  • Install the bencoding.dictionary module. If you need help here is a "How To" guide.
  • You can now use the module via the commonJS require method, example shown below.


var notify = require('bencoding.localnotify');

Now we have the module installed and avoid in our project we can start to use the components, see the feature guide below for details.

benCoding.localNotify How To Example

For detailed documentation please reference this project's documentation folder. A code "How To" example is provided in the app.js located in the project's example folder.

Methods


activeScheduledNotifications

You can use this method to query your scheduled local notifications. Simply call this method and provide a callback method similar to what is shown below. The callback will be returned a collection with all of the available information about your scheduled local notifications.

The below sample shows how to create a callback that queries your scheduled local notifications. You can then loop through the results in your callback function.



	//This is our callback for our scheduled local notification query
	function localNotificationCallback(e){
		Ti.API.info("Let's how many local notifications we have scheduled'");
		Ti.API.info("Scheduled LocalNotification = " + e.scheduledCount);	
		alert("You have " +  e.scheduledCount + " Scheduled LocalNotification");

		var test = JSON.stringify(e);
		Ti.API.info("results stringified" + test);
	};

	//Call this method and return a callback with the results
	notify.activeScheduledNotifications(localNotificationCallback);

returnScheduledNotifications

This method allows you to query your scheduled notification similar to activeScheduledNotifications but without the callback.

Simply call the returnScheduledNotifications method and you will be returned a collection with all of the available information about your scheduled local notifications.

The below sample shows how to get a resultset by using this method.



	//Call this method to return a collection with information on your scheduled notifications
	var results = notify.returnScheduledNotifications();
	Ti.API.info("Let's how many local notifications we have scheduled'");
	Ti.API.info("Scheduled LocalNotification = " + results.scheduledCount);	
	alert("You have " +  results.scheduledCount + " Scheduled LocalNotification");
	var test = JSON.stringify(results);
	Ti.API.info("results stringified" + test);	

findLocalNotificationsByKey

This method allows you to query your scheduled notification similar to activeScheduledNotifications but with using a value and key combination. This method will return all notifications that has a matching UserInfo with the provided value and key combination. In the below example, we return all notifications that have a userInfo.category property with a value of foo.

The below sample shows how to get a resultset by using this method.



	//Call this method to return a collection with information on your scheduled notifications
	var results = notify.findLocalNotificationsByKey("foo","category");
	Ti.API.info("Let's how many local notifications we have scheduled'");
	Ti.API.info("Scheduled LocalNotification = " + results.scheduledCount);	
	alert("You have " +  results.scheduledCount + " Scheduled LocalNotification");
	var test = JSON.stringify(results);
	Ti.API.info("results stringified" + test);

searchLocalNotificationsByKey

This method works in the same way as findLocalNotificationsByKey, but provides a callback method.

In the below example, a callback is returned with all notifications that have a userInfo.category property with a value of foo.

The below sample shows how to get a resultset by using this method.



	//This is our callback for our scheduled local notification query
	function localNotificationCallback(e){
		Ti.API.info("Let's how many local notifications we have scheduled'");
		Ti.API.info("Scheduled LocalNotification = " + e.scheduledCount);	
		alert("You have " +  e.scheduledCount + " Scheduled LocalNotification");

		var test = JSON.stringify(e);
		Ti.API.info("results stringified" + test);
	};

	//Call this method and return a callback with the results
	notify.searchLocalNotificationsByKey("foo","category",localNotificationCallback);

cancelLocalNotificationByKey

This method allows you to cancel a specific scheduled local notification using any key defined in the userInfo dictionary.

In the above scheduleLocalNotification example you see we use userInfo:{"id":1,"hello":"world","category":"foo"} when creating the notification.

You can use any of the defined keys to cancel an event. In the below example, you see that a key of "category" is provided along with the value of "foo". This will remove all notifications that meet this criteria.

The method cancelLocalNotificationByKey returns an integer with the number of scheduled notifications canceled. Since you can schedule one or more notifications with the same property information this will let you know how many where removed without having to re-run the activeScheduledNotifications method.

The below sample shows how to cancel a local notification with the userInfo "category" property set to "foo". After canceling we query the saved notifications to confirm the cancel was successful.



	//We are going to remove all of the LocalNotifications scheduled with a userInfo id value of 1
	var canceledCount =  notify.cancelLocalNotificationByKey("foo","category");
	alert("You have canceled " + canceledCount + " notifications");
	//Now query the scheduled notifications to make sure our local notification was canceled
	notify.activeScheduledNotifications(localNotificationCallback);

Licensing & Support

This project is licensed under the OSI approved Apache Public License (version 2). For details please see the license associated with each project.

Developed by Ben Bahrenburg available on twitter @benCoding

Learn More


Twitter

Please consider following the @benCoding Twitter for updates and more about Titanium.

Blog

For module updates, Titanium tutorials and more please check out my blog at benCoding.Com.

localnotify's People

Contributors

benbahrenburg avatar brownemint avatar

Stargazers

 avatar Anthony Chung avatar Jason David Miller avatar Irving Emmanuel González avatar buhe avatar Vitor Emanuel Batista avatar lmy avatar Mahmoud Kamal avatar Nick den Engelsman avatar Josh Lambert avatar Joe Webber avatar Abdulatif Henno avatar Konstantin Büschel avatar Tobias Høegh avatar  avatar Ravindra Kumar avatar  avatar Projets DIY avatar Damien Laureaux avatar Stefan Malzner avatar  avatar Steven avatar Joe Spano avatar Jonathan avatar David Bankier avatar Iñaki Abete avatar  avatar Flavio Maria De Stefano avatar Kristján Ingi Mikaelsson avatar Chris Mendez avatar Digitalico avatar  avatar Daisuke Sugai avatar Daniel Lin avatar Andrea Giglio avatar mayulu avatar Dário avatar Joseph avatar Petr Chalupny avatar Christopher Beloch avatar  avatar Alper Dincer avatar Akin avatar HH avatar Garrett Langley avatar Edgar Wong Baxter Jr. avatar Josh Miller avatar Ket Majmudar avatar Michel Melo avatar Adam Paxton avatar  avatar Sean avatar samuele coppede avatar John Feezer IV avatar  avatar John Gould avatar David Sullivan avatar hyokos avatar flypigz avatar José Carlos Andreu avatar  avatar Gustavo Rodriguez Baldera avatar Gergely Cziva avatar Torsten Stelling avatar  avatar  avatar Atsushi Kataoka avatar  avatar Aaron K Saunders avatar Fabio Ribeiro avatar Dan Tamas avatar bsoft avatar Tatsuya Arai avatar Kelvin Jones avatar Achraf Bouyakhsass avatar

Watchers

 avatar John Feezer IV avatar Ket Majmudar avatar mayulu avatar Aaron K Saunders avatar Joe Chavez avatar James Cloos avatar  avatar  avatar Gustavo Rodriguez Baldera avatar Danny avatar Vitor Emanuel Batista avatar Mark Tangpus avatar  avatar Andrea Giglio avatar  avatar

localnotify's Issues

Sound not playing

Hi am trying to play a sound when notification arrives, I have kept .caf file in asset/Radar.caf and in asset/iphone/Radar.caf and used the following code,

        notify.scheduleLocalNotification({
            alertBody: "TEST",
            alertAction: "Ok",
            userInfo: {"id": id},
            sound: "Radar.caf" or "iphone/Radar.caf", //Have tried both
            date: new Date(time)
        });

It was mentioned that relative to resources folder we need to specify the sound file path. As far in my Resources folder Radar.caf file is in iphone/Radar.caf.
Is it possible to play sound/am I doing any wrong?

scheduleLocalNotification ignored hasOwnProperty

Hi Ben,

in my app I have prototyped Object with method 'isEmpty'. If I use your method scheduleLocalNotification then comes the message:
Property list invalid for format: 200 (property lists cannot contain objects of type 'CFType')

If I debug my notification I see a property 'isEmpty'. It seems your method doesn't test if it is a real property …
This is my workaround:

var notification = {
    alertAction : event.label,
    alertBody : event.label + ': ' + formatTime(event.duration),
    date : new Date(new Date().getTime() + event.duration * 1000),
    category : 'labortimer',
    sound : event.sound,
    identifier : id,
    userInfo : {
      id : id 
    }
};
for (var key in notification) {
    if (!notification.hasOwnProperty(key))
    delete notification[key];
}
Notify.scheduleLocalNotification(notification);

couldn't find module

Hi Ben

I am new to Titanium and have been trying to use you module bencoding.localnotify after installing it as described at
http://docs.appcelerator.com/titanium/2.1/#!/guide/Using_a_Module under the heading "Installing a module for a single project" - I took both approaches
and thereafter using it as per the heading "Configuring your app to use a module" and your example.

the build goes just fine
but still, the app fails with the error
[ERROR] Script Error = Couldn't find module: bencoding.localnotify.
in console log

what am I missing?

Repeat Notification over a month or two

is that possible to repeat a notification lets say every day at 10 AM for 1-2 months?

How to set the end date so that beyond that it wont trigger any notification?

kindly suggest

How do I catch the notification event?

This is a great module, thanks for putting it together. I have it working within my app just fine, but how would I catch the notification event, say when the user clicks the 'ok' button on the notification and the app opens? Ideally you would direct the user to a specific section of the app or show them a specific message related to their notification. Is there a method for doing this with the LocalNotify module? Is it a matter of setting up an event listener? If so, what event am I listening for?

Vibrate when local notification received

Hi... is it possible to vibrate the device when a local notification arrives?. I hope there is no option for it in current version. Am not good with Objective C, is it possible to tweak code for this functionality or else its already available? I have the following code working good,

notify.scheduleLocalNotification({
            alertBody: "TEST",
            alertAction: "Ok",
            userInfo: {"id": id},
            sound: "Radar.caf",
            date: new Date(time)
        });

Thanks in advance.

The sound property wasn't working?

This is my codes above.


notify.scheduleLocalNotification({
alertBody:'message',
alertAction:"OK",
sound:"/ringtones/sound.m4r",
date:new Date((new Date()).getTime() + 5000),
userInfo:{"id":1}
});


Increase badge count

Is it possible to increase badge count by one for each notification? When I set badge: 1 it always set the badge to 1, even if the badge count already is 1.

Notification firing directly when app go to bg

Hi, and thanks for this module :)
But I got a problem using this one :S
When I create my localnotification, I did it like you on your readme.md, but I do the notify on background service. After making my app go to bg the notification is firing :/
It doesn't care about the fireDate :(

I'm on Titanium SDK 3.4.0 GA and IOS 8.

Here is my code :

var params = JSON.stringify({
    "dateTime": now,
    "area": e.row.children[0].text,
    "type": e.row.children[1].text
});

Ti.App.Properties.setString("params", params);
var service = Ti.App.iOS.registerBackgroundService({url:'../js/notif.js'});

In notify.js :

var params = JSON.parse(Ti.App.Properties.getString("params"));

var notify = require('bencoding.localnotify');

notify.scheduleLocalNotification({
    alertBody:L("Event happening soon at ") + params.area + ' ( ' + L(params.type) + ' )',
    alertAction:"Just a test",
    userInfo:{"id":1,"hello":"world"},
    date:params.dateTime
});

Thanks for helping 👍

64bit

Could you please update for 64bit?

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.