Commit c05c4e14 by Sebastián Katzer

Added `json` property to pass custom data through the notification

parent 97b5c60b
...@@ -57,6 +57,7 @@ More informations can be found [here](https://build.phonegap.com/plugins/331). ...@@ -57,6 +57,7 @@ More informations can be found [here](https://build.phonegap.com/plugins/331).
- **[bugfix:]** Callbacks are called with the ID as a number and not as a string. - **[bugfix:]** Callbacks are called with the ID as a number and not as a string.
- [enhancement:] The background callback on Android is called, even the app is not running when the notification is tapped. - [enhancement:] The background callback on Android is called, even the app is not running when the notification is tapped.
- [enhancement:] Notifications are repeated more precisely. - [enhancement:] Notifications are repeated more precisely.
- [feature:] Added `json` property to pass custom data through the notification.
#### Version 0.6.3 (12.12.2013) #### Version 0.6.3 (12.12.2013)
- [bugfix:] Black screen on Android. - [bugfix:] Black screen on Android.
...@@ -112,7 +113,8 @@ window.plugin.notification.local.add({ ...@@ -112,7 +113,8 @@ window.plugin.notification.local.add({
title: String, // The title of the message title: String, // The title of the message
repeat: String, // Has the options of 'hourly', 'daily', 'weekly', 'monthly', 'yearly' repeat: String, // Has the options of 'hourly', 'daily', 'weekly', 'monthly', 'yearly'
badge: Number, // Displays number badge to notification badge: Number, // Displays number badge to notification
sound: String, // A sound to be played (iOS & Android) 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 autoCancel: Boolean, // Setting this flag and the notification is automatically canceled when the user clicks it
foreground: String, // A javascript function to be called if the app is running foreground: String, // A javascript function to be called if the app is running
background: String, // A javascript function to be called if the app is in the background background: String, // A javascript function to be called if the app is in the background
...@@ -165,6 +167,19 @@ window.plugin.notification.local.add({ message: 'Great app!' }); ...@@ -165,6 +167,19 @@ window.plugin.notification.local.add({ message: 'Great app!' });
```javascript ```javascript
window.plugin.notification.local.add({ sound: null }); window.plugin.notification.local.add({ sound: null });
``` ```
#### Pass data through the notification
```javascript
window.plugin.notification.local.add({
id: 1,
message: 'I love BlackBerry!',
json: { test: 123 },
foreground: 'forground'
});
function foreground (id, json) {
console.log(id, JSON.parse(json).test);
}
```
## Platform specifics ## Platform specifics
......
...@@ -209,6 +209,13 @@ public class Options { ...@@ -209,6 +209,13 @@ public class Options {
} }
/** /**
* Gibt die zusätzlichen Daten als String an.
*/
public String getJSON () {
return options.optString("json", "");
}
/**
* Gibt den Zahlwert des Icons an. * Gibt den Zahlwert des Icons an.
* *
* @param {String} className * @param {String} className
......
...@@ -185,7 +185,10 @@ public class Receiver extends BroadcastReceiver { ...@@ -185,7 +185,10 @@ public class Receiver extends BroadcastReceiver {
// after reboot, LocalNotification.webView is always null // after reboot, LocalNotification.webView is always null
// may be call foreground callback later // may be call foreground callback later
if (!TextUtils.isEmpty(function) && LocalNotification.webView != null) { if (!TextUtils.isEmpty(function) && LocalNotification.webView != null) {
LocalNotification.webView.sendJavascript("setTimeout('" + function + "(\"" + options.getId() + "\")',0)"); String params = "\"" + options.getId() + "\",\\'" + JSONObject.quote(options.getJSON()) + "\\'.replace(/(^\"|\"$)/g, \\'\\')";
String js = "setTimeout('" + function + "(" + params + ")',0)";
LocalNotification.webView.sendJavascript(js);
} }
} }
} }
\ No newline at end of file
...@@ -79,7 +79,8 @@ public class ReceiverActivity extends Activity { ...@@ -79,7 +79,8 @@ public class ReceiverActivity extends Activity {
if (TextUtils.isEmpty(function)) if (TextUtils.isEmpty(function))
return; return;
final String js = "setTimeout('" + function + "(\"" + options.getId() + "\")',0)"; String params = "\"" + options.getId() + "\",\\'" + JSONObject.quote(options.getJSON()) + "\\'.replace(/(^\"|\"$)/g, \\'\\')";
final String js = "setTimeout('" + function + "(" + params + ")',0)";
// after reboot, LocalNotification.webView is always null // after reboot, LocalNotification.webView is always null
// call background callback later // call background callback later
......
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
// Schlüssel-Präfix für alle archivierten Meldungen // Schlüssel-Präfix für alle archivierten Meldungen
NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION"; NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION";
@implementation APPLocalNotification @implementation APPLocalNotification
/** /**
...@@ -167,8 +166,14 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION"; ...@@ -167,8 +166,14 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION";
NSString* bg = [options objectForKey:@"background"]; NSString* bg = [options objectForKey:@"background"];
NSString* fg = [options objectForKey:@"foreground"]; NSString* fg = [options objectForKey:@"foreground"];
NSString* ac = [options objectForKey:@"autoCancel"]; NSString* ac = [options objectForKey:@"autoCancel"];
NSString* js = [options objectForKey:@"json"];
return [NSDictionary dictionaryWithObjectsAndKeys:id, @"id", bg, @"background", fg, @"foreground", ac, @"autoCancel", nil];
return [NSDictionary dictionaryWithObjectsAndKeys:
id, @"id",
bg, @"background",
fg, @"foreground",
ac, @"autoCancel",
js, @"json", nil];
} }
/** /**
...@@ -229,6 +234,7 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION"; ...@@ -229,6 +234,7 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION";
UILocalNotification* notification = [localNotification object]; UILocalNotification* notification = [localNotification object];
NSString* id = [notification.userInfo objectForKey:@"id"]; NSString* id = [notification.userInfo objectForKey:@"id"];
NSString* json = [notification.userInfo objectForKey:@"json"];
NSString* callbackType = isActive ? @"foreground" : @"background"; NSString* callbackType = isActive ? @"foreground" : @"background";
NSString* callbackFn = [notification.userInfo objectForKey:callbackType]; NSString* callbackFn = [notification.userInfo objectForKey:callbackType];
BOOL autoCancel = [[notification.userInfo objectForKey:@"autoCancel"] boolValue]; BOOL autoCancel = [[notification.userInfo objectForKey:@"autoCancel"] boolValue];
...@@ -240,7 +246,8 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION"; ...@@ -240,7 +246,8 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION";
if (![self strIsNullOrEmpty:callbackFn]) if (![self strIsNullOrEmpty:callbackFn])
{ {
NSString* js = [NSString stringWithFormat:@"setTimeout('%@(\"%@\")',0)", callbackFn, id]; NSString* params = [NSString stringWithFormat:@"\"%@\",\\'%@\\'", id, json];
NSString* js = [NSString stringWithFormat:@"setTimeout('%@(%@)',0)", callbackFn, params];
[self.commandDelegate evalJs:js]; [self.commandDelegate evalJs:js];
} }
......
...@@ -75,6 +75,12 @@ namespace De.APPPlant.Cordova.Plugin.LocalNotification ...@@ -75,6 +75,12 @@ namespace De.APPPlant.Cordova.Plugin.LocalNotification
public string Repeat { get; set; } public string Repeat { get; set; }
/// <summary> /// <summary>
/// Notification specific data
/// </summary>
[DataMember(IsRequired = false, Name = "json")]
public string JSON { get; set; }
/// <summary>
/// Message-ID /// Message-ID
/// </summary> /// </summary>
[DataMember(IsRequired = false, Name = "id")] [DataMember(IsRequired = false, Name = "id")]
......
...@@ -38,6 +38,7 @@ LocalNotification.prototype = { ...@@ -38,6 +38,7 @@ LocalNotification.prototype = {
autoCancel: false, autoCancel: false,
badge: 0, badge: 0,
id: '0', id: '0',
json: '',
repeat: '', repeat: '',
background: '', background: '',
foreground: '' foreground: ''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment