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
04e5ef63
Commit
04e5ef63
authored
Aug 16, 2017
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new getType() method and implemented isPresent, isScheduled, isTriggered for Windows
parent
0224f67c
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
140 additions
and
178 deletions
+140
-178
APPLocalNotification.h
src/ios/APPLocalNotification.h
+2
-10
APPLocalNotification.m
src/ios/APPLocalNotification.m
+23
-93
UNUserNotificationCenter+APPLocalNotification.h
src/ios/UNUserNotificationCenter+APPLocalNotification.h
+4
-10
UNUserNotificationCenter+APPLocalNotification.m
src/ios/UNUserNotificationCenter+APPLocalNotification.m
+24
-55
LocalNotificationProxy.js
src/windows/LocalNotificationProxy.js
+15
-0
Manager.cs
...Proxy/LocalNotificationProxy/LocalNotification/Manager.cs
+30
-0
Notification.cs
.../LocalNotificationProxy/LocalNotification/Notification.cs
+1
-1
LocalNotificationProxy.cs
...ionProxy/LocalNotificationProxy/LocalNotificationProxy.cs
+10
-0
local-notification-core.js
www/local-notification-core.js
+16
-7
local-notification.js
www/local-notification.js
+15
-2
No files found.
src/ios/APPLocalNotification.h
View file @
04e5ef63
...
...
@@ -51,12 +51,8 @@
// Cancel all notifications
-
(
void
)
cancelAll
:(
CDVInvokedUrlCommand
*
)
command
;
// If a notification with an ID is present
-
(
void
)
isPresent
:(
CDVInvokedUrlCommand
*
)
command
;
// If a notification with an ID is scheduled
-
(
void
)
isScheduled
:(
CDVInvokedUrlCommand
*
)
command
;
// If a notification with an ID is triggered
-
(
void
)
isTriggered
:(
CDVInvokedUrlCommand
*
)
command
;
// Notification type
-
(
void
)
type
:(
CDVInvokedUrlCommand
*
)
command
;
// List of all notification IDs
-
(
void
)
ids
:(
CDVInvokedUrlCommand
*
)
command
;
...
...
@@ -67,10 +63,6 @@
// Notification by id
-
(
void
)
notification
:(
CDVInvokedUrlCommand
*
)
command
;
// Scheduled notification by id
-
(
void
)
scheduledNotification
:(
CDVInvokedUrlCommand
*
)
command
;
// Triggered notification by id
-
(
void
)
triggeredNotification
:(
CDVInvokedUrlCommand
*
)
command
;
// List of notifications by id
-
(
void
)
notifications
:(
CDVInvokedUrlCommand
*
)
command
;
...
...
src/ios/APPLocalNotification.m
View file @
04e5ef63
...
...
@@ -242,58 +242,32 @@
}
/**
*
If a notification by ID is present
.
*
Get type of notification
.
*
* @param [
Number ]
id The ID of the notification.
* @param [
Int ]
id The ID of the notification.
*
* @return [ Void ]
*/
-
(
void
)
isPresent
:(
CDVInvokedUrlCommand
*
)
command
{
[
self
exist
:
command
byType
:
NotifcationTypeAll
];
}
/**
* If a notification by ID is scheduled.
*
* @param [ Number ]id The ID of the notification.
*
* @return [ Void ]
*/
-
(
void
)
isScheduled
:(
CDVInvokedUrlCommand
*
)
command
{
[
self
exist
:
command
byType
:
NotifcationTypeScheduled
];
}
/**
* Check if a notification with an ID is triggered.
*
* @param [ Number ]id The ID of the notification.
*
* @return [ Void ]
*/
-
(
void
)
isTriggered
:(
CDVInvokedUrlCommand
*
)
command
{
[
self
exist
:
command
byType
:
NotifcationTypeTriggered
];
}
/**
* Check if a notification exists by ID and type.
*
* @param [ APPNotificationType ] type The type of notifications to look for.
*
* @return [ Void ]
*/
-
(
void
)
exist
:(
CDVInvokedUrlCommand
*
)
command
byType
:(
APPNotificationType
)
type
;
-
(
void
)
type
:(
CDVInvokedUrlCommand
*
)
command
{
[
self
.
commandDelegate
runInBackground
:
^
{
NSNumber
*
id
=
[
command
argumentAtIndex
:
0
];
BOOL
exist
=
[
_center
notificationExist
:
id
type
:
type
];
NSString
*
type
;
switch
([
_center
getTypeOfNotificationWithId
:
id
])
{
case
NotifcationTypeScheduled
:
type
=
@"scheduled"
;
break
;
case
NotifcationTypeTriggered
:
type
=
@"triggered"
;
break
;
default:
type
=
@"unknown"
;
}
CDVPluginResult
*
result
;
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAs
Bool
:
exist
];
messageAs
String
:
type
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
command
.
callbackId
];
...
...
@@ -361,53 +335,16 @@
*/
-
(
void
)
notification
:
(
CDVInvokedUrlCommand
*
)
command
{
[
self
notification
:
command
byType
:
NotifcationTypeAll
];
}
/**
* Scheduled notification by id.
*
* @param [ Number ] id The id of the notification to return.
*
* @return [ Void ]
*/
-
(
void
)
scheduledNotification
:
(
CDVInvokedUrlCommand
*
)
command
{
[
self
notification
:
command
byType
:
NotifcationTypeScheduled
];
}
/**
* Triggered notification by id.
*
* @param [ Number ] id The id of the notification to return.
*
* @return [ Void ]
*/
-
(
void
)
triggeredNotification
:
(
CDVInvokedUrlCommand
*
)
command
{
[
self
notification
:
command
byType
:
NotifcationTypeTriggered
];
}
/**
* Notification by type and id.
*
* @param [ APPNotificationType ] type The type of notifications to look for.
*
* @return [ Void ]
*/
-
(
void
)
notification
:
(
CDVInvokedUrlCommand
*
)
command
byType
:
(
APPNotificationType
)
type
;
{
[
self
.
commandDelegate
runInBackground
:
^
{
NSArray
*
ids
=
command
.
arguments
;
NSArray
*
notifications
;
notifications
=
[
_center
getNotificationOptionsBy
Type
:
type
and
Id
:
ids
];
notifications
=
[
_center
getNotificationOptionsById
:
ids
];
CDVPluginResult
*
result
;
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsDictionary
:[
notifications
firstObject
]];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
command
.
callbackId
];
}];
...
...
@@ -450,7 +387,7 @@
}
/**
* List of notifications by type
and
id.
* List of notifications by type
or
id.
*
* @param [ APPNotificationType ] type The type of notifications to look for.
*
...
...
@@ -463,18 +400,11 @@
NSArray
*
ids
=
command
.
arguments
;
NSArray
*
notifications
;
if
(
type
==
NotifcationTypeAll
&&
ids
.
count
==
0
)
{
notifications
=
[
_center
getNotificationOptions
];
}
else
if
(
type
==
NotifcationTypeAll
)
{
if
(
ids
.
count
>
0
)
{
notifications
=
[
_center
getNotificationOptionsById
:
ids
];
}
else
if
(
ids
.
count
==
0
)
{
notifications
=
[
_center
getNotificationOptionsByType
:
type
];
}
else
{
notifications
=
[
_center
getNotificationOptionsByType
:
type
andId
:
ids
];
notifications
=
[
_center
getNotificationOptionsByType
:
type
];
}
CDVPluginResult
*
result
;
...
...
src/ios/UNUserNotificationCenter+APPLocalNotification.h
View file @
04e5ef63
...
...
@@ -28,7 +28,8 @@ extern NSString * const kAPPGeneralCategory;
typedef
NS_ENUM
(
NSUInteger
,
APPNotificationType
)
{
NotifcationTypeAll
=
0
,
NotifcationTypeScheduled
=
1
,
NotifcationTypeTriggered
=
2
NotifcationTypeTriggered
=
2
,
NotifcationTypeUnknown
=
3
};
#define APPNotificationType_DEFINED
...
...
@@ -44,15 +45,10 @@ typedef NS_ENUM(NSUInteger, APPNotificationType) {
// List of all notification IDs from given type
-
(
NSArray
*
)
getNotificationIdsByType
:(
APPNotificationType
)
type
;
// Find out if notification with ID exists
-
(
BOOL
)
notificationExist
:(
NSNumber
*
)
id
;
// Find out if notification with ID and type exists
-
(
BOOL
)
notificationExist
:(
NSNumber
*
)
id
type
:(
APPNotificationType
)
type
;
// Find notification by ID
-
(
UNNotificationRequest
*
)
getNotificationWithId
:(
NSNumber
*
)
id
;
// Find notification
by ID and type
-
(
UNNotificationRequest
*
)
getNotificationWithId
:(
NSNumber
*
)
id
andType
:(
APPNotificationType
)
type
;
// Find notification
type by ID
-
(
APPNotificationType
)
getTypeOfNotificationWithId
:(
NSNumber
*
)
id
;
// Property list from all local notifications
-
(
NSArray
*
)
getNotificationOptions
;
...
...
@@ -60,8 +56,6 @@ typedef NS_ENUM(NSUInteger, APPNotificationType) {
-
(
NSArray
*
)
getNotificationOptionsById
:(
NSArray
*
)
ids
;
// Property list from all local notifications with type constraint
-
(
NSArray
*
)
getNotificationOptionsByType
:(
APPNotificationType
)
type
;
// Property list from given local notifications with type constraint
-
(
NSArray
*
)
getNotificationOptionsByType
:(
APPNotificationType
)
type
andId
:(
NSArray
*
)
ids
;
// Clear specified notfication
-
(
void
)
clearNotification
:(
UNNotificationRequest
*
)
notification
;
...
...
src/ios/UNUserNotificationCenter+APPLocalNotification.m
View file @
04e5ef63
...
...
@@ -185,29 +185,6 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
return
ids
;
}
/*
* If the notification with the specified ID does exists.
*
* @param id
* Notification ID
*/
-
(
BOOL
)
notificationExist
:
(
NSNumber
*
)
id
{
return
[
self
getNotificationWithId
:
id
]
!=
NULL
;
}
/* If the notification with specified ID and type exists.
*
* @param id
* Notification ID
* @param type
* Notification life cycle type
*/
-
(
BOOL
)
notificationExist
:
(
NSNumber
*
)
id
type
:
(
APPNotificationType
)
type
{
return
[
self
getNotificationWithId
:
id
andType
:
type
]
!=
NULL
;
}
/**
* Find notification by ID.
*
...
...
@@ -216,34 +193,39 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
*/
-
(
UNNotificationRequest
*
)
getNotificationWithId
:
(
NSNumber
*
)
id
{
return
[
self
getNotificationWithId
:
id
andType
:
NotifcationTypeAll
];
}
/*
* Find notification by ID and type.
*
* @param id
* Notification ID
* @param type
* Notification life cycle type
*/
-
(
UNNotificationRequest
*
)
getNotificationWithId
:
(
NSNumber
*
)
id
andType
:
(
APPNotificationType
)
type
{
NSArray
*
notifications
=
[
self
getNotificationsByType
:
type
];
NSArray
*
notifications
=
[
self
getNotifications
];
for
(
UNNotificationRequest
*
notification
in
notifications
)
{
NSString
*
fid
=
[
NSString
stringWithFormat
:
@"%@"
,
notification
.
options
.
id
];
if
([
fid
isEqualToString
:[
id
stringValue
]])
{
return
notification
;
}
}
return
NULL
;
}
/**
* Find notification type by ID
*/
-
(
APPNotificationType
)
getTypeOfNotificationWithId
:
(
NSNumber
*
)
id
{
NSArray
*
ids
=
[
self
getNotificationIdsByType
:
NotifcationTypeTriggered
];
if
([
ids
containsObject
:
id
])
return
NotifcationTypeTriggered
;
ids
=
[
self
getNotificationIdsByType
:
NotifcationTypeScheduled
];
if
([
ids
containsObject
:
id
])
return
NotifcationTypeScheduled
;
return
NotifcationTypeUnknown
;
}
/**
* List of properties from all notifications.
*/
-
(
NSArray
*
)
getNotificationOptions
...
...
@@ -278,29 +260,16 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
*/
-
(
NSArray
*
)
getNotificationOptionsById
:
(
NSArray
*
)
ids
{
return
[
self
getNotificationOptionsByType
:
NotifcationTypeAll
andId
:
ids
];
}
/**
* List of properties from given local notifications.
*
* @param type
* Notification life cycle type
* @param ids
* Notification IDs
*/
-
(
NSArray
*
)
getNotificationOptionsByType
:
(
APPNotificationType
)
type
andId
:
(
NSArray
*
)
ids
{
NSArray
*
notifications
=
[
self
getNotificationsByType
:
type
];
NSArray
*
notifications
=
[
self
getNotifications
];
NSMutableArray
*
options
=
[[
NSMutableArray
alloc
]
init
];
for
(
UNNotificationRequest
*
notification
in
notifications
)
{
if
([
ids
containsObject
:
notification
.
options
.
id
])
{
[
options
addObject
:
notification
.
options
.
userInfo
];
}
}
return
options
;
}
...
...
src/windows/LocalNotificationProxy.js
View file @
04e5ef63
...
...
@@ -98,6 +98,21 @@ exports.schedule = function (success, error, args) {
};
/**
* Get the type of notification.
*
* @param [ Function ] success Success callback
* @param [ Function ] error Error callback
* @param [ Array ] args Interface arguments
*
* @return [ Void ]
*/
exports
.
type
=
function
(
success
,
error
,
args
)
{
var
type
=
impl
.
type
(
args
[
0
]);
success
(
type
);
};
/**
* List of all notification ids.
*
* @param [ Function ] success Success callback
...
...
src/windows/LocalNotificationProxy/LocalNotificationProxy/LocalNotification/Manager.cs
View file @
04e5ef63
...
...
@@ -238,5 +238,35 @@ namespace LocalNotificationProxy.LocalNotification
return
null
;
}
/// <summary>
/// Gets the type (scheduled, triggered or unknown).
/// </summary>
/// <param name="id">The ID of the notification to find for.</param>
/// <returns>The type of the notification or unknown type.</returns>
public
Notification
.
Type
GetType
(
string
id
)
{
var
scheduled
=
ToastNotifier
.
GetScheduledToastNotifications
();
foreach
(
var
toast
in
scheduled
)
{
if
(
toast
.
Tag
==
id
)
{
return
Notification
.
Type
.
Scheduled
;
}
}
var
triggered
=
ToastNotificationManager
.
History
.
GetHistory
();
foreach
(
var
toast
in
triggered
)
{
if
(
toast
.
Tag
==
id
)
{
return
Notification
.
Type
.
Triggered
;
}
}
return
Notification
.
Type
.
Unknown
;
}
}
}
src/windows/LocalNotificationProxy/LocalNotificationProxy/LocalNotification/Notification.cs
View file @
04e5ef63
...
...
@@ -46,7 +46,7 @@
public
enum
Type
{
All
,
Scheduled
,
Triggered
All
,
Scheduled
,
Triggered
,
Unknown
}
public
Options
Options
{
get
;
private
set
;
}
...
...
src/windows/LocalNotificationProxy/LocalNotificationProxy/LocalNotificationProxy.cs
View file @
04e5ef63
...
...
@@ -50,6 +50,16 @@ namespace LocalNotificationProxy
}
/// <summary>
/// Gets the type of the notification specified by ID.
/// </summary>
/// <param name="id">The ID of the notification to find for.</param>
/// <returns>The type (scheduled, triggered or unknown).</returns>
public
string
Type
(
int
id
)
{
return
this
.
manager
.
GetType
(
id
.
ToString
()).
ToString
().
ToLower
();
}
/// <summary>
/// List of all notifiation by id.
/// </summary>
/// <returns>List of numbers</returns>
...
...
www/local-notification-core.js
View file @
04e5ef63
...
...
@@ -185,24 +185,33 @@ exports.cancelAll = function (callback, scope) {
* @return [ Void ]
*/
exports
.
isPresent
=
function
(
id
,
callback
,
scope
)
{
this
.
exec
(
'isPresent'
,
id
,
callback
,
scope
);
var
fn
=
this
.
createCallbackFn
(
callback
,
scope
);
this
.
getType
(
id
,
function
(
type
)
{
fn
(
type
!=
'unknown'
);
});
};
/**
* Check if a notification
is scheduled
.
* Check if a notification
has a given type
.
*
* @param [ Int ] id The ID of the notification.
* @param [ String ] type The type of the notification.
* @param [ Function ] callback The function to be exec as the callback.
* @param [ Object ] scope The callback function's scope.
*
* @return [ Void ]
*/
exports
.
isScheduled
=
function
(
id
,
callback
,
scope
)
{
this
.
exec
(
'isScheduled'
,
id
,
callback
,
scope
);
exports
.
hasType
=
function
(
id
,
type
,
callback
,
scope
)
{
var
fn
=
this
.
createCallbackFn
(
callback
,
scope
);
this
.
getType
(
id
,
function
(
type2
)
{
fn
(
type
==
type2
);
});
};
/**
*
Check if a notification was triggered
.
*
Get the type (triggered, scheduled) for the notification
.
*
* @param [ Int ] id The ID of the notification.
* @param [ Function ] callback The function to be exec as the callback.
...
...
@@ -210,8 +219,8 @@ exports.isScheduled = function (id, callback, scope) {
*
* @return [ Void ]
*/
exports
.
isTriggered
=
function
(
id
,
callback
,
scope
)
{
this
.
exec
(
'
isTriggered
'
,
id
,
callback
,
scope
);
exports
.
getType
=
function
(
id
,
callback
,
scope
)
{
this
.
exec
(
'
type
'
,
id
,
callback
,
scope
);
};
/**
...
...
www/local-notification.js
View file @
04e5ef63
...
...
@@ -147,7 +147,7 @@ exports.isPresent = function (id, callback, scope) {
* @return [ Void ]
*/
exports
.
isScheduled
=
function
(
id
,
callback
,
scope
)
{
this
.
core
.
isScheduled
(
id
,
callback
,
scope
);
this
.
core
.
hasType
(
id
,
'scheduled'
,
callback
,
scope
);
};
/**
...
...
@@ -160,7 +160,20 @@ exports.isScheduled = function (id, callback, scope) {
* @return [ Void ]
*/
exports
.
isTriggered
=
function
(
id
,
callback
,
scope
)
{
this
.
core
.
isTriggered
(
id
,
callback
,
scope
);
this
.
core
.
hasType
(
id
,
'triggered'
,
callback
,
scope
);
};
/**
* Get the type (triggered, scheduled) for the notification.
*
* @param [ Int ] id The ID of the notification.
* @param [ Function ] callback The function to be exec as the callback.
* @param [ Object ] scope The callback function's scope.
*
* @return [ Void ]
*/
exports
.
getType
=
function
(
id
,
callback
,
scope
)
{
this
.
core
.
getType
(
id
,
callback
,
scope
);
};
/**
...
...
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