Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cordova-plugin-local-notifications
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nabil Sadki
cordova-plugin-local-notifications
Commits
4e6ec9bb
Commit
4e6ec9bb
authored
Feb 27, 2014
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new methods `isScheduled` and `getScheduledIds` (#97 #95)
parent
5c903678
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
157 additions
and
4 deletions
+157
-4
README.md
README.md
+18
-0
LocalNotification.java
src/android/LocalNotification.java
+45
-0
APPLocalNotification.h
src/ios/APPLocalNotification.h
+4
-0
APPLocalNotification.m
src/ios/APPLocalNotification.m
+47
-0
LocalNotification.cs
src/wp8/LocalNotification.cs
+20
-4
local-notification.js
www/local-notification.js
+23
-0
No files found.
README.md
View file @
4e6ec9bb
...
...
@@ -58,6 +58,8 @@ More informations can be found [here](https://build.phonegap.com/plugins/413).
-
[
bugfix:
]
Callbacks for non-repeating notifications were not called if they were not created in the current app instance on iOS.
-
[
enhancement:
]
Added 'secondly' and 'minutely' as new repeat time aliases.
-
[
bugfix:
]
`sound:null`
didnt work for Android. The default sound was played.
-
[
feature:
]
New interface
`isScheduled`
to check wether a notification with an ID is pending.
-
[
feature:
]
New interface
`getScheduledIds`
to retrieve a list with all currently pending notifications.
#### Version 0.7.2 (09.02.2014)
-
[
enhancement:
]
Avoid blocking the main thread (on Android)
**(dpogue)**
.
...
...
@@ -178,6 +180,22 @@ window.plugin.notification.local.on_callback_ = function (id, state, json) {};
```
**Note:**
The
*ontrigger*
callback is only invoked in background if the app is not suspended!
### isScheduled()
Checks wether a notification with an ID is scheduled. It takes the ID as an argument and a callback function to be called with the result.
```
javascript
window
.
plugin
.
notification
.
local
.
isScheduled
(
id
,
function
(
isScheduled
)
{
});
```
### getScheduledIds()
Checks wether a notification with an ID is scheduled. It takes a callback function to be called with the result as an array.
```
javascript
window
.
plugin
.
notification
.
local
.
getScheduledIds
(
function
(
pendingIds
)
{
});
```
### getDefaults()
Gives an overview about all available notification properties for the platform and their default values. The function returns an object.
```
javascript
...
...
src/android/LocalNotification.java
View file @
4e6ec9bb
...
...
@@ -29,6 +29,7 @@ import org.apache.cordova.CallbackContext;
import
org.apache.cordova.CordovaInterface
;
import
org.apache.cordova.CordovaPlugin
;
import
org.apache.cordova.CordovaWebView
;
import
org.apache.cordova.PluginResult
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -107,6 +108,20 @@ public class LocalNotification extends CordovaPlugin {
return
true
;
}
if
(
action
.
equalsIgnoreCase
(
"isScheduled"
))
{
String
id
=
args
.
optString
(
0
);
isScheduled
(
id
,
callbackContext
);
return
true
;
}
if
(
action
.
equalsIgnoreCase
(
"getScheduledIds"
))
{
getScheduledIds
(
callbackContext
);
return
true
;
}
// Returning false results in a "MethodNotFound" error.
return
false
;
}
...
...
@@ -188,6 +203,36 @@ public class LocalNotification extends CordovaPlugin {
}
/**
* Checks wether a notification with an ID is scheduled.
*
* @param id
* The notification ID to be check.
* @param callbackContext
*/
public
static
void
isScheduled
(
String
id
,
CallbackContext
callbackContext
)
{
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
boolean
isScheduled
=
alarms
.
containsKey
(
id
);
PluginResult
result
=
new
PluginResult
(
PluginResult
.
Status
.
OK
,
isScheduled
);
callbackContext
.
sendPluginResult
(
result
);
}
/**
* Retrieves a list with all currently pending notifications.
*
* @param callbackContext
*/
public
static
void
getScheduledIds
(
CallbackContext
callbackContext
)
{
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
JSONArray
pendingIds
=
new
JSONArray
(
alarmIds
);
callbackContext
.
success
(
pendingIds
);
}
/**
* Persist the information of this alarm to the Android Shared Preferences.
* This will allow the application to restore the alarm upon device reboot.
* Also this is used by the cancelAll method.
...
...
src/ios/APPLocalNotification.h
View file @
4e6ec9bb
...
...
@@ -35,5 +35,9 @@ extern NSString *const kAPP_LOCALNOTIFICATION;
-
(
void
)
cancel
:(
CDVInvokedUrlCommand
*
)
command
;
// Entfernt alle registrierten Einträge
-
(
void
)
cancelAll
:(
CDVInvokedUrlCommand
*
)
command
;
// Checks wether a notification with an ID is scheduled
-
(
void
)
isScheduled
:(
CDVInvokedUrlCommand
*
)
command
;
// Retrieves a list with all currently pending notifications
-
(
void
)
getScheduledIds
:(
CDVInvokedUrlCommand
*
)
command
;
@end
src/ios/APPLocalNotification.m
View file @
4e6ec9bb
...
...
@@ -111,6 +111,53 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION";
}
/**
* Checks wether a notification with an ID is scheduled.
*/
-
(
void
)
isScheduled
:(
CDVInvokedUrlCommand
*
)
command
{
[
self
.
commandDelegate
runInBackground
:
^
{
CDVPluginResult
*
result
;
NSArray
*
arguments
=
[
command
arguments
];
NSString
*
id
=
[
arguments
objectAtIndex
:
0
];
NSString
*
key
=
[
kAPP_LOCALNOTIFICATION
stringByAppendingString
:
id
];
NSData
*
data
=
[[
NSUserDefaults
standardUserDefaults
]
objectForKey
:
key
];
bool
isScheduled
=
data
!=
NULL
;
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsBool
:
isScheduled
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
command
.
callbackId
];
}];
}
/**
* Retrieves a list with all currently pending notifications.
*/
-
(
void
)
getScheduledIds
:(
CDVInvokedUrlCommand
*
)
command
{
[
self
.
commandDelegate
runInBackground
:
^
{
NSMutableArray
*
scheduledIds
=
[[
NSMutableArray
alloc
]
init
];
NSDictionary
*
entries
=
[[
NSUserDefaults
standardUserDefaults
]
dictionaryRepresentation
];
CDVPluginResult
*
result
;
for
(
NSString
*
key
in
[
entries
allKeys
])
{
if
([
key
hasPrefix
:
kAPP_LOCALNOTIFICATION
])
{
NSString
*
id
=
[
key
stringByReplacingOccurrencesOfString
:
kAPP_LOCALNOTIFICATION
withString
:
@""
];
[
scheduledIds
addObject
:
id
];
}
}
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsArray
:
scheduledIds
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
command
.
callbackId
];
}];
}
/**
* Entfernt den zur ID passenden Eintrag.
*
* @param {NSString} id Die ID der Notification
...
...
src/wp8/LocalNotification.cs
View file @
4e6ec9bb
...
...
@@ -41,7 +41,7 @@ namespace Cordova.Extension.Commands
/// <summary>
/// Sets application live tile
/// </summary>
public
void
add
(
string
jsonArgs
)
public
void
add
(
string
jsonArgs
)
{
string
[]
args
=
JsonHelper
.
Deserialize
<
string
[
]>
(
jsonArgs
);
Options
options
=
JsonHelper
.
Deserialize
<
Options
>(
args
[
0
]);
...
...
@@ -66,7 +66,7 @@ namespace Cordova.Extension.Commands
/// <summary>
/// Clears the application live tile
/// </summary>
public
void
cancel
(
string
jsonArgs
)
public
void
cancel
(
string
jsonArgs
)
{
string
[]
args
=
JsonHelper
.
Deserialize
<
string
[
]>
(
jsonArgs
);
string
notificationID
=
args
[
0
];
...
...
@@ -79,7 +79,7 @@ namespace Cordova.Extension.Commands
/// <summary>
/// Clears the application live tile
/// </summary>
public
void
cancelAll
(
string
jsonArgs
)
public
void
cancelAll
(
string
jsonArgs
)
{
// Application Tile is always the first Tile, even if it is not pinned to Start.
ShellTile
AppTile
=
ShellTile
.
ActiveTiles
.
First
();
...
...
@@ -107,9 +107,25 @@ namespace Cordova.Extension.Commands
}
/// <summary>
/// Checks wether a notification with an ID is scheduled
/// </summary>
public
void
isScheduled
(
string
jsonArgs
)
{
DispatchCommandResult
();
}
/// <summary>
/// Retrieves a list with all currently pending notifications
/// </summary>
public
void
getScheduledIds
(
string
jsonArgs
)
{
DispatchCommandResult
();
}
/// <summary>
/// Creates tile data
/// </summary>
private
FlipTileData
CreateTileData
(
Options
options
)
private
FlipTileData
CreateTileData
(
Options
options
)
{
FlipTileData
tile
=
new
FlipTileData
();
...
...
www/local-notification.js
View file @
4e6ec9bb
...
...
@@ -146,6 +146,29 @@ LocalNotification.prototype = {
},
/**
* @async
*
* Retrieves a list with all currently pending notifications.
*
* @param {Function} callback
*/
getScheduledIds
:
function
(
callback
)
{
cordova
.
exec
(
callback
,
null
,
'LocalNotification'
,
'getScheduledIds'
,
[]);
},
/**
* @async
*
* Checks wether a notification with an ID is scheduled.
*
* @param {String} id
* @param {Function} callback
*/
isScheduled
:
function
(
id
,
callback
)
{
cordova
.
exec
(
callback
,
null
,
'LocalNotification'
,
'isScheduled'
,
[
id
.
toString
()]);
},
/**
* Occurs when a notification was added.
*
* @param {String} id The ID of the notification
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment