Commit adf62bf2 authored by Sebastián Katzer's avatar Sebastián Katzer
Browse files

Add `autoCancel` flag to indicate that the notification shall be automatically...

Add `autoCancel` flag to indicate that the notification shall be automatically canceled when the user clicks it
parent b129a48e
Loading
Loading
Loading
Loading
+11 −9
Changes for README.md: 11 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ More informations can be found [here](https://build.phonegap.com/plugins/331).
- [bugfix:] App throws an error on iOS if `message` is null.
- [bugfix:] Removed extra line break on iOS if `title` is null or empty.
- [bugfix:] Notification on iOS will be canceled if a new one with the same ID was added.
- [enhancement:] Added `autoCancel` flag.

#### Version 0.6.3 (12.12.2013)
- [bugfix:] Black screen on Android.
@@ -99,15 +100,16 @@ All properties are optional. If no date object is given, the notification will p

```javascript
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 daily', 'weekly',''monthly','yearly')
    badge:      Number, // displays number badge to notification
    sound:      String, // a sound to be played (iOS & Android)
    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
    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 daily', 'weekly',''monthly','yearly')
    badge:      Number,  // Displays number badge to notification
    sound:      String,  // A sound to be played (iOS & Android)
    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
    background: String,  // A javascript function to be called if the app is in the background
});
```
**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.
+11 −8
Changes for src/android/Options.java: 11 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -38,10 +38,8 @@ import android.net.Uri;
public class Options {

    private JSONObject options = new JSONObject();
    private String id          = null;
    private String packageName = null;
    private long interval      = 0;
    private long date          = 0;

    Options (Activity activity) {
        packageName = activity.getPackageName();
@@ -58,8 +56,6 @@ public class Options {
        String repeat = options.optString("repeat");

        this.options = options;
        date         = options.optLong("date") * 1000;
        id           = options.optString("id");

        if (repeat.equalsIgnoreCase("daily")) {
            interval = AlarmManager.INTERVAL_DAY;
@@ -85,7 +81,7 @@ public class Options {
     * Gibt die Zeit in Sekunden an, wann die Notification aufpoppen soll.
     */
    public long getDate() {
        return date;
        return options.optLong("date", 0) * 1000;
    }

    /**
@@ -103,14 +99,14 @@ public class Options {
     * Gibt die Nachricht der Notification an.
     */
    public String getMessage () {
        return options.optString("message");
        return options.optString("message", "");
    }

    /**
     * Gibt den Titel der Notification an.
     */
    public String getTitle () {
        return options.optString("title");
        return options.optString("title", "");
    }

    /**
@@ -184,7 +180,14 @@ public class Options {
     * Gibt die Callback-ID des PluginResults an.
     */
    public String getId () {
        return id;
        return options.optString("id", "0");
    }

    /**
     * Gibt an, ob die Notification automatisch geschlossen werden soll, wenn der Benutzer darauf klickt.
     */
    public Boolean getAutoCancel () {
        return options.optBoolean("autoCancel", false);
    }

    /**
+2 −1
Changes for src/android/Receiver.java: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -121,7 +121,8 @@ public class Receiver extends BroadcastReceiver {
        .setNumber(options.getBadge())
        .setTicker(options.getTitle())
        .setSmallIcon(options.getIcon())
        .setSound(options.getSound());
        .setSound(options.getSound())
        .setAutoCancel(options.getAutoCancel());

        setClickEvent(notification);

+12 −5
Changes for src/ios/APPLocalNotification.m: 12 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -23,8 +23,6 @@

@interface APPLocalNotification (Private)

// Entfernt die zur ID passende Meldung
 - (void) cancelNotificationWithId:(NSString*)notificationId;
- (NSMutableDictionary*) repeatDict;
// Alle zusätzlichen Metadaten der Notification als Hash
- (NSDictionary*) userDict:(NSMutableDictionary*)options;
@@ -58,7 +56,9 @@
}

/**
 * Entfernt die zur ID passende Meldung.
 * Entfernt den anhand der ID angegebenen Eintrag.
 *
 * @param {NSString} id Die ID der Notification
 */
- (void) cancel:(CDVInvokedUrlCommand*)command
{
@@ -79,7 +79,7 @@
}

/**
 * Entfernt die zur ID passende Meldung.
 * Entfernt den anhand der ID angegebenen Eintrag.
 *
 * @param {NSString} id Die ID der Notification
 */
@@ -127,8 +127,9 @@
    NSString* id = [options objectForKey:@"id"];
    NSString* bg = [options objectForKey:@"background"];
    NSString* fg = [options objectForKey:@"foreground"];
    NSString* ac = [options objectForKey:@"autoCancel"];

    return [NSDictionary dictionaryWithObjectsAndKeys:id, @"id", bg, @"background", fg, @"foreground", nil];
    return [NSDictionary dictionaryWithObjectsAndKeys:id, @"id", bg, @"background", fg, @"foreground", ac, @"autoCancel", nil];
}

/**
@@ -191,6 +192,12 @@
    NSString* id                      = [notification.userInfo objectForKey:@"id"];
    NSString* callbackType            = isActive ? @"foreground" : @"background";
    NSString* callbackFn              = [notification.userInfo objectForKey:callbackType];
    BOOL autoCancel                   = [[notification.userInfo objectForKey:@"autoCancel"] boolValue];

    if (autoCancel && !isActive)
    {
        [[UIApplication sharedApplication] cancelLocalNotification:notification];
    }

    if (callbackFn && callbackFn.length > 0)
    {
+6 −0
Changes for src/wp8/LocalNotificationOptions.cs: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -92,6 +92,12 @@ namespace De.APPPlant.Cordova.Plugin.LocalNotification
        [DataMember(IsRequired = false, Name = "foreground")]
        public string Foreground { get; set; }

        /// <summary>
        /// Setting this flag will make it so the notification is automatically canceled when the user clicks it
        /// </summary>
        [DataMember(IsRequired = false, Name = "autoCancel")]
        public bool AutoCancel { get; set; }

        /// <summary>
        /// The notification small background image to be displayed
        /// </summary>
Loading