|
|
12 vuotta sitten | |
|---|---|---|
| src | 12 vuotta sitten | |
| www | 12 vuotta sitten | |
| LICENSE | 12 vuotta sitten | |
| README.md | 12 vuotta sitten | |
| plugin.xml | 12 vuotta sitten |
A bunch of local notification plugins for Cordova 3.x.x
by Sebastián Katzer (github.com/katzer)
iOS
See Local and Push Notification Programming Guide for detailed informations and screenshots.
Android (SDK >=11)
See Notification Guide for detailed informations and screenshots.
WP8
See Local notifications for Windows Phone for detailed informations and screenshots.
Windows Phone 8.0 has no notification center. Instead local notifications are realized through live tiles updates.
Cordova will check all dependencies and install them if they are missing.
Through the Command-line Interface:
cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications.git
Through the Command-line Interface:
cordova plugin rm de.appplant.cordova.plugin.local-notification
Add the following xml to your config.xml to always use the latest version of this plugin:
<gap:plugin name="de.appplant.cordova.plugin.local-notification" />
or to use this exact version:
<gap:plugin name="de.appplant.cordova.plugin.local-notification" version="0.7.0" />
More informations can be found here.
onadd was called each time after a repeating message was triggered (Android)ongoing attribute was ignored.oncancel wasnt fired if autoCancel was set to true.Note: The new way of callback registration will be not compatible with previous versions! See #62
message is null.title is null or empty.autoCancel flag.cancel on iOS did not work.json property to pass custom data through the notification.smallImage.ongoing.cancel on Android with an invalid String as ID does not throw an error anymore.RECEIVE_BOOT_COMPLETEDpermission on Android.cancel on iOS did not work do to wrong param type.cancel & cancelAll remove the notification(s) from notification center as well on Android.add() function now returns the id of the created notification.title property.cancel on iOS did not work do to wrong dict key.The plugin creates the object window.plugin.notification.local with the following methods:
The method allows to add a custom notification. It takes an hash as an argument to specify the notification's properties and returns the ID for the notification.
All properties are optional. If no date object is given, the notification will pop-up immediately.
window.plugin.notification.local.add({
id: String, // A unique id of the notifiction
date: Date, // This expects a date object
message: String, // The message that is displayed
title: String, // The title of the message
repeat: String, // Has the options of 'hourly', 'daily', 'weekly', 'monthly', 'yearly'
badge: Number, // Displays number badge to notification
sound: String, // A sound to be played
json: String, // Data to be passed through the notification
autoCancel: Boolean, // Setting this flag and the notification is automatically canceled when the user clicks it
ongoing: Boolean, // Prevent clearing of notification (Android only)
});
Note: On Android the notification id needs to be a string which can be converted to a number. If the ID has an invalid format, it will be ignored, but canceling the notification will fail.
The method cancels a notification which was previously added. It takes the ID of the notification as an argument.
window.plugin.notification.local.cancel(String);
The method cancels all notifications which were previously added by the application.
window.plugin.notification.local.cancelAll();
There are 4 different callback types available. For each of them one listener can be specified. The listener has to be a function and takes the following arguments:
json: A custom (JSON) string
window.plugin.notification.local.on_callback_ = function (id, state, json) {};
Gives an overview about all available notification properties for the platform and their default values. The function returns an object.
window.plugin.notification.local.getDefaults();
Overrides the default properties. The function takes an object as argument.
window.plugin.notification.local.setDefaults(Object);
var now = new Date().getTime(),
_60_seconds_from_now = new Date(now + 60*1000);
window.plugin.notification.local.add({
id: 1, // is converted to a string
title: 'Reminder',
message: 'Dont forget to buy some flowers.',
repeat: 'weekly',
date: _60_seconds_from_now
});
window.plugin.notification.local.add({ message: 'Great app!' });
window.plugin.notification.local.add({ sound: null });
window.plugin.notification.local.onadd = function (id, state, json) {};
window.plugin.notification.local.add({
id: 1,
message: 'I love BlackBerry!',
json: { test: 123 }
});
window.plugin.notification.local.onclick = function (id, state, json) {
console.log(id, JSON.parse(json).test);
}
window.plugin.notification.local.setDefaults({ autoCancel: true });
By default all notifications will display the app icon. But an specific icon can be defined through the icon and smallIcon properties.
/**
* Displays the <package.name>.R.drawable.ic_launcher icon
*/
window.plugin.notification.local.add({ icon: 'ic_launcher' });
/**
* Displays the android.R.drawable.ic_dialog_email icon
*/
window.plugin.notification.local.add({ smallIcon: 'ic_dialog_email' });
The sound must be a absolute or relative Uri pointing to the sound file. The default sound is RingtoneManager.TYPE_NOTIFICATION.
/**
* Plays the `beep.mp3` sound if the notification pop's up
*/
window.plugin.notification.local.add({ sound: 'android.resource://' + package_name + '/raw/beep' });
/**
* Plays the `RingtoneManager.TYPE_ALARM` sound
*/
window.plugin.notification.local.add({ sound: 'TYPE_ALARM' });
Note: Local sound files must be placed into the res-folder and not into the assets-folder.
You can package the audio data in an aiff, wav, or caf file. Then, in Xcode, add the sound file to your project as a nonlocalized resource of the application bundle. You may use the afconvert tool to convert sounds.
/**
* Plays the sound if the notification pop's up
*/
window.plugin.notification.local.add({ sound: 'sub.caf' });
Note: The right to play notification sounds in the notification center settings has to be granted.
Note: Custom sounds must be under 30 seconds when played. If a custom sound is over that limit, the default system sound is played instead.
LiveTile's have the ability to display images for different sizes. These images can be defined through the smallImage, image and wideImage properties.
An image must be defined as a relative or absolute URI.
/**
* Displays the application icon as the livetile's background image
*/
window.plugin.notification.local.add({ image: 'appdata:ApplicationIcon.png' })
All images can be restored to the default ones by canceling the notification.
To specify a custom interval, the repeat property can be assigned with an number in minutes.
/**
* Schedules the notification quarterly every 15 mins
*/
window.plugin.notification.local.add({ repeat: 15 });
The right to play notification sounds in the notification center settings has to be granted.
An application can only display one notification at a time. Each time a new notification has to be added, the application live tile's data will be overwritten by the new ones.
Along with Cordova 3.2 and Windows Phone 8 the version.bat script has to be renamed to version.
On Mac or Linux
mv platforms/wp8/cordova/version.bat platforms/wp8/cordova/version
On Windows
ren platforms\wp8\cordova\version.bat platforms\wp8\cordova\version
The launch mode for the main activity has to be set to singleInstance
<activity ... android:launchMode="singleInstance" ... />
git checkout -b my-new-feature)git commit -am 'Add some feature')git push origin my-new-feature)This software is released under the Apache 2.0 License.