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
5759483e
Commit
5759483e
authored
Feb 19, 2018
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disable support for implicit action group decleration
parent
c008cc68
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
230 additions
and
75 deletions
+230
-75
LocalNotification.java
src/android/LocalNotification.java
+51
-14
Options.java
src/android/notification/Options.java
+13
-11
ActionGroup.java
src/android/notification/action/ActionGroup.java
+18
-0
AssetUtil.java
src/android/notification/util/AssetUtil.java
+0
-0
APPLocalNotification.m
src/ios/APPLocalNotification.m
+43
-12
APPNotificationContent.m
src/ios/APPNotificationContent.m
+1
-1
APPNotificationOptions.h
src/ios/APPNotificationOptions.h
+4
-4
APPNotificationOptions.m
src/ios/APPNotificationOptions.m
+6
-4
UNNotificationRequest+APPLocalNotification.h
src/ios/UNNotificationRequest+APPLocalNotification.h
+0
-3
UNUserNotificationCenter+APPLocalNotification.h
src/ios/UNUserNotificationCenter+APPLocalNotification.h
+5
-15
UNUserNotificationCenter+APPLocalNotification.m
src/ios/UNUserNotificationCenter+APPLocalNotification.m
+59
-5
local-notification.js
www/local-notification.js
+30
-6
No files found.
src/android/LocalNotification.java
View file @
5759483e
...
...
@@ -131,17 +131,16 @@ public class LocalNotification extends CordovaPlugin {
if
(
action
.
equals
(
"ready"
))
{
deviceready
();
}
else
if
(
action
.
equals
IgnoreCase
(
"check"
))
{
if
(
action
.
equals
(
"check"
))
{
check
(
command
);
}
else
if
(
action
.
equals
IgnoreCase
(
"request"
))
{
if
(
action
.
equals
(
"request"
))
{
request
(
command
);
}
else
if
(
action
.
equalsIgnoreCase
(
"actions"
))
{
actions
(
args
.
optJSONObject
(
0
));
command
.
success
();
if
(
action
.
equals
(
"actions"
))
{
actions
(
args
,
command
);
}
else
if
(
action
.
equals
IgnoreCase
(
"schedule"
))
{
if
(
action
.
equals
(
"schedule"
))
{
schedule
(
args
);
check
(
command
);
}
else
...
...
@@ -228,9 +227,7 @@ public class LocalNotification extends CordovaPlugin {
*/
private
void
check
(
CallbackContext
command
)
{
boolean
allowed
=
getNotMgr
().
hasPermission
();
PluginResult
result
=
new
PluginResult
(
PluginResult
.
Status
.
OK
,
allowed
);
command
.
sendPluginResult
(
result
);
success
(
command
,
allowed
);
}
/**
...
...
@@ -246,13 +243,41 @@ public class LocalNotification extends CordovaPlugin {
/**
* Register action group.
*
* @param args The action group spec.
* @param args The exec() arguments in JSON form.
* @param command The callback context used when calling back into
* JavaScript.
*/
private
void
actions
(
JSONObject
args
)
{
ActionGroup
group
=
ActionGroup
.
parse
(
cordova
.
getActivity
(),
args
);
private
void
actions
(
JSONArray
args
,
CallbackContext
command
)
{
int
task
=
args
.
optInt
(
0
);
ActionGroup
group
;
JSONObject
spec
;
boolean
found
;
String
id
;
switch
(
task
)
{
case
1
:
spec
=
args
.
optJSONObject
(
1
);
group
=
ActionGroup
.
parse
(
cordova
.
getActivity
(),
spec
);
if
(
group
!=
null
)
ActionGroup
.
register
(
group
);
command
.
success
();
break
;
case
-
1
:
id
=
args
.
optString
(
1
);
ActionGroup
.
unregister
(
id
);
command
.
success
();
break
;
case
0
:
id
=
args
.
optString
(
1
);
found
=
ActionGroup
.
isRegistered
(
id
);
success
(
command
,
found
);
if
(
group
!=
null
)
{
ActionGroup
.
register
(
group
);
break
;
}
}
...
...
@@ -485,6 +510,18 @@ public class LocalNotification extends CordovaPlugin {
}
/**
* Invoke success callback with a single boolean argument.
*
* @param command The callback context used when calling back into
* JavaScript.
* @param arg The single argument to pass through.
*/
private
void
success
(
CallbackContext
command
,
boolean
arg
)
{
PluginResult
result
=
new
PluginResult
(
PluginResult
.
Status
.
OK
,
arg
);
command
.
sendPluginResult
(
result
);
}
/**
* Fire given event on JS side. Does inform all event listeners.
*
* @param event The event name.
...
...
src/android/notification/Options.java
View file @
5759483e
...
...
@@ -596,24 +596,26 @@ public final class Options {
* Gets the list of actions to display.
*/
Action
[]
getActions
()
{
String
groupId
=
options
.
optString
(
"actionGroupId"
,
null
);
JSONArray
actions
=
options
.
optJSONArray
(
"actions"
);
Object
value
=
options
.
opt
(
"actions"
);
String
groupId
=
null
;
JSONArray
actions
=
null
;
ActionGroup
group
=
null
;
if
(
actions
!=
null
&&
actions
.
length
()
>
0
)
{
group
=
ActionGroup
.
parse
(
context
,
options
);
if
(
value
instanceof
String
)
{
groupId
=
(
String
)
value
;
}
else
if
(
value
instanceof
JSONArray
)
{
actions
=
(
JSONArray
)
value
;
}
if
(
group
==
null
&&
group
Id
!=
null
)
{
if
(
groupId
!=
null
)
{
group
=
ActionGroup
.
lookup
(
groupId
);
}
else
if
(
actions
!=
null
&&
actions
.
length
()
>
0
)
{
group
=
ActionGroup
.
parse
(
context
,
options
);
}
if
(
group
!=
null
)
{
ActionGroup
.
register
(
group
);
return
group
.
getActions
();
}
return
null
;
return
(
group
!=
null
)
?
group
.
getActions
()
:
null
;
}
/**
...
...
src/android/notification/action/ActionGroup.java
View file @
5759483e
...
...
@@ -73,6 +73,24 @@ public final class ActionGroup {
}
/**
* Unregister the action group.
*
* @param id The id of the action group to remove.
*/
public
static
void
unregister
(
String
id
)
{
groups
.
remove
(
id
);
}
/**
* Check if a action group with that id is registered.
*
* @param id The id of the action group to check for.
*/
public
static
boolean
isRegistered
(
String
id
)
{
return
groups
.
containsKey
(
id
);
}
/**
* Creates an action group by parsing the specified action specs.
*
* @param spec The action group spec containing the id and list of actions.
...
...
src/android/notification/util/AssetUtil.java
View file @
5759483e
src/ios/APPLocalNotification.m
View file @
5759483e
...
...
@@ -176,7 +176,7 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
-
(
void
)
clearAll
:(
CDVInvokedUrlCommand
*
)
command
{
[
self
.
commandDelegate
runInBackground
:
^
{
[
_center
clear
All
Notifications
];
[
_center
clearNotifications
];
[
self
clearApplicationIconBadgeNumber
];
[
self
fireEvent
:
@"clearall"
];
[
self
execCallback
:
command
];
...
...
@@ -217,7 +217,7 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
-
(
void
)
cancelAll
:(
CDVInvokedUrlCommand
*
)
command
{
[
self
.
commandDelegate
runInBackground
:
^
{
[
_center
cancel
All
Notifications
];
[
_center
cancelNotifications
];
[
self
clearApplicationIconBadgeNumber
];
[
self
fireEvent
:
@"cancelall"
];
[
self
execCallback
:
command
];
...
...
@@ -411,12 +411,7 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
BOOL
enabled
=
settings
.
notificationCenterSetting
==
UNNotificationSettingEnabled
;
BOOL
permitted
=
authorized
&&
enabled
;
CDVPluginResult
*
result
;
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsBool
:
permitted
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
command
.
callbackId
];
[
self
execCallback
:
command
arg
:
permitted
];
}];
}
...
...
@@ -443,14 +438,37 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
-
(
void
)
actions
:
(
CDVInvokedUrlCommand
*
)
command
{
[
self
.
commandDelegate
runInBackground
:
^
{
NSDictionary
*
options
=
command
.
arguments
[
0
];
int
task
=
[
command
.
arguments
[
0
]
intValue
];
APPNotificationContent
*
notification
;
NSDictionary
*
options
;
NSString
*
identifier
;
BOOL
found
;
switch
(
task
)
{
case
1
:
options
=
command
.
arguments
[
1
];
notification
=
[[
APPNotificationContent
alloc
]
initWithOptions
:
options
];
[
_center
addNotificationCategory
:
notification
.
category
];
[
_center
addActionGroup
:
notification
.
category
];
[
self
execCallback
:
command
];
break
;
case
-
1
:
identifier
=
command
.
arguments
[
1
];
[
_center
removeActionGroup
:
identifier
];
[
self
execCallback
:
command
];
break
;
case
0
:
identifier
=
command
.
arguments
[
1
];
found
=
[
_center
hasActionGroup
:
identifier
];
[
self
execCallback
:
command
arg
:
found
];
break
;
}
}];
}
...
...
@@ -470,8 +488,6 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
UNNotificationRequest
*
request
=
notification
.
request
;
NSString
*
event
=
[
request
wasUpdated
]
?
@"update"
:
@"add"
;
[
_center
addNotificationCategory
:
notification
.
category
];
[
_center
addNotificationRequest
:
request
withCompletionHandler
:
^
(
NSError
*
e
)
{
__strong
APPLocalNotification
*
strongSelf
=
weakSelf
;
[
strongSelf
fireEvent
:
event
notification
:
request
];
...
...
@@ -642,6 +658,21 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
}
/**
* Invokes the callback with a single boolean parameter.
*
* @return [ Void ]
*/
-
(
void
)
execCallback
:
(
CDVInvokedUrlCommand
*
)
command
arg
:
(
BOOL
)
arg
{
CDVPluginResult
*
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsBool
:
arg
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
command
.
callbackId
];
}
/**
* Fire general event.
*
* @param [ NSString* ] event The name of the event to fire.
...
...
src/ios/APPNotificationContent.m
View file @
5759483e
...
...
@@ -64,7 +64,7 @@ static char optionsKey;
self
.
sound
=
options
.
sound
;
self
.
badge
=
options
.
badge
;
self
.
attachments
=
options
.
attachments
;
self
.
categoryIdentifier
=
options
.
category
Id
;
self
.
categoryIdentifier
=
options
.
actionGroup
Id
;
}
#pragma mark -
...
...
src/ios/APPNotificationOptions.h
View file @
5759483e
...
...
@@ -25,7 +25,7 @@
@property
(
readonly
,
getter
=
id
)
NSNumber
*
id
;
@property
(
readonly
,
getter
=
identifier
)
NSString
*
identifier
;
@property
(
readonly
,
getter
=
categoryId
)
NSString
*
category
Id
;
@property
(
readonly
,
getter
=
actionGroupId
)
NSString
*
actionGroup
Id
;
@property
(
readonly
,
getter
=
title
)
NSString
*
title
;
@property
(
readonly
,
getter
=
subtitle
)
NSString
*
subtitle
;
@property
(
readonly
,
getter
=
badge
)
NSNumber
*
badge
;
...
...
@@ -34,10 +34,10 @@
@property
(
readonly
,
getter
=
priority
)
int
priority
;
@property
(
readonly
,
getter
=
sound
)
UNNotificationSound
*
sound
;
@property
(
readonly
,
getter
=
userInfo
)
NSDictionary
*
userInfo
;
@property
(
readonly
,
getter
=
actions
)
NSArray
<
UNNotificationAction
*>
*
actions
;
@property
(
readonly
,
getter
=
attachments
)
NSArray
<
UNNotificationAttachment
*>
*
attachments
;
@property
(
readonly
,
getter
=
actions
)
NSArray
<
UNNotificationAction
*>*
actions
;
@property
(
readonly
,
getter
=
attachments
)
NSArray
<
UNNotificationAttachment
*>*
attachments
;
-
(
id
)
initWithDict
:(
NSDictionary
*
)
dict
;
-
(
id
)
initWithDict
:(
NSDictionary
*
)
dict
;
-
(
UNNotificationTrigger
*
)
trigger
;
@end
src/ios/APPNotificationOptions.m
View file @
5759483e
...
...
@@ -52,11 +52,8 @@ static NSInteger WEEKDAYS[8] = { 0, 2, 3, 4, 5, 6, 7, 1 };
-
(
id
)
initWithDict
:(
NSDictionary
*
)
dictionary
{
self
=
[
self
init
];
self
.
dict
=
dictionary
;
[
self
actions
];
return
self
;
}
...
...
@@ -154,8 +151,13 @@ static NSInteger WEEKDAYS[8] = { 0, 2, 3, 4, 5, 6, 7, 1 };
*
* @return [ NSString* ]
*/
-
(
NSString
*
)
category
Id
-
(
NSString
*
)
actionGroup
Id
{
id
actions
=
[
dict
objectForKey
:
@"actions"
];
if
([
actions
isKindOfClass
:
NSString
.
class
])
return
actions
;
NSString
*
value
=
[
dict
objectForKey
:
@"actionGroupId"
];
return
value
.
length
?
value
:
kAPPGeneralCategory
;
...
...
src/ios/UNNotificationRequest+APPLocalNotification.h
View file @
5759483e
...
...
@@ -25,11 +25,8 @@
@interface
UNNotificationRequest
(
APPLocalNotification
)
// The options provided by the plug-in
-
(
APPNotificationOptions
*
)
options
;
// If the notification was updated
-
(
BOOL
)
wasUpdated
;
// Encode the user info dict to JSON
-
(
NSString
*
)
encodeToJSON
;
@end
src/ios/UNUserNotificationCenter+APPLocalNotification.h
View file @
5759483e
...
...
@@ -37,34 +37,24 @@ typedef NS_ENUM(NSUInteger, APPNotificationType) {
@property
(
readonly
,
getter
=
getNotifications
)
NSArray
*
localNotifications
;
@property
(
readonly
,
getter
=
getNotificationIds
)
NSArray
*
localNotificationIds
;
// Register general notification category to listen for dismiss actions
-
(
void
)
registerGeneralNotificationCategory
;
// Add the specified category to the list of categories
-
(
void
)
addNotificationCategory
:(
UNNotificationCategory
*
)
category
;
-
(
void
)
addActionGroup
:(
UNNotificationCategory
*
)
category
;
-
(
void
)
removeActionGroup
:(
NSString
*
)
identifier
;
-
(
BOOL
)
hasActionGroup
:(
NSString
*
)
identifier
;
// List of all notification IDs from given type
-
(
NSArray
*
)
getNotificationIdsByType
:(
APPNotificationType
)
type
;
// Find notification by ID
-
(
UNNotificationRequest
*
)
getNotificationWithId
:(
NSNumber
*
)
id
;
// Find notification type by ID
-
(
APPNotificationType
)
getTypeOfNotificationWithId
:(
NSNumber
*
)
id
;
// Property list from all local notifications
-
(
NSArray
*
)
getNotificationOptions
;
// Property list from given local notifications
-
(
NSArray
*
)
getNotificationOptionsById
:(
NSArray
*
)
ids
;
// Property list from all local notifications with type constraint
-
(
NSArray
*
)
getNotificationOptionsByType
:(
APPNotificationType
)
type
;
// Clear specified notfication
-
(
void
)
clearNotification
:(
UNNotificationRequest
*
)
notification
;
// Clear all notfications
-
(
void
)
clearAllNotifications
;
-
(
void
)
clearNotifications
;
// Cancel specified notfication
-
(
void
)
cancelNotification
:(
UNNotificationRequest
*
)
notification
;
// Cancel all notfications
-
(
void
)
cancelAllNotifications
;
-
(
void
)
cancelNotifications
;
@end
src/ios/UNUserNotificationCenter+APPLocalNotification.m
View file @
5759483e
...
...
@@ -56,7 +56,7 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
*
* @return [ Void ]
*/
-
(
void
)
add
NotificationCategory
:
(
UNNotificationCategory
*
)
category
-
(
void
)
add
ActionGroup
:
(
UNNotificationCategory
*
)
category
{
if
(
!
category
)
return
;
...
...
@@ -64,7 +64,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
[
self
getNotificationCategoriesWithCompletionHandler
:
^
(
NSSet
<
UNNotificationCategory
*>
*
set
)
{
NSMutableSet
*
categories
=
[
NSMutableSet
setWithSet
:
set
];
for
(
UNNotificationCategory
*
item
in
categories
)
{
for
(
UNNotificationCategory
*
item
in
categories
)
{
if
([
category
.
identifier
isEqualToString
:
item
.
identifier
])
{
[
categories
removeObject
:
item
];
break
;
...
...
@@ -76,6 +77,58 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
}];
}
/**
* Remove if the specified category does exist.
*
* @param [ NSString* ] identifier The category id to remove.
*
* @return [ Void ]
*/
-
(
void
)
removeActionGroup
:
(
NSString
*
)
identifier
{
[
self
getNotificationCategoriesWithCompletionHandler
:
^
(
NSSet
<
UNNotificationCategory
*>
*
set
)
{
NSMutableSet
*
categories
=
[
NSMutableSet
setWithSet
:
set
];
for
(
UNNotificationCategory
*
item
in
categories
)
{
if
([
item
.
identifier
isEqualToString
:
identifier
])
{
[
categories
removeObject
:
item
];
break
;
}
}
[
self
setNotificationCategories
:
categories
];
}];
}
/**
* Check if the specified category does exist.
*
* @param [ NSString* ] identifier The category id to check for.
*
* @return [ Void ]
*/
-
(
BOOL
)
hasActionGroup
:
(
NSString
*
)
identifier
{
dispatch_semaphore_t
sema
=
dispatch_semaphore_create
(
0
);
__block
BOOL
found
=
NO
;
[
self
getNotificationCategoriesWithCompletionHandler
:
^
(
NSSet
<
UNNotificationCategory
*>
*
items
)
{
for
(
UNNotificationCategory
*
item
in
items
)
{
if
([
item
.
identifier
isEqualToString
:
identifier
])
{
found
=
YES
;
dispatch_semaphore_signal
(
sema
);
break
;
}
}
}];
dispatch_semaphore_wait
(
sema
,
DISPATCH_TIME_FOREVER
);
return
found
;
}
#pragma mark -
#pragma mark LocalNotifications
...
...
@@ -101,7 +154,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
dispatch_semaphore_t
sema
=
dispatch_semaphore_create
(
0
);
[
self
getDeliveredNotificationsWithCompletionHandler
:
^
(
NSArray
<
UNNotification
*>
*
delivered
)
{
for
(
UNNotification
*
notification
in
delivered
)
{
for
(
UNNotification
*
notification
in
delivered
)
{
[
notifications
addObject
:
notification
.
request
];
}
dispatch_semaphore_signal
(
sema
);
...
...
@@ -276,7 +330,7 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/*
* Clear all notfications.
*/
-
(
void
)
clear
All
Notifications
-
(
void
)
clearNotifications
{
[
self
removeAllDeliveredNotifications
];
}
...
...
@@ -298,7 +352,7 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/*
* Cancel all notfications.
*/
-
(
void
)
cancel
All
Notifications
-
(
void
)
cancelNotifications
{
[
self
removeAllPendingNotificationRequests
];
[
self
removeAllDeliveredNotifications
];
...
...
www/local-notification.js
View file @
5759483e
...
...
@@ -24,7 +24,6 @@ var exec = require('cordova/exec'),
// Defaults
exports
.
_defaults
=
{
actionGroupId
:
null
,
actions
:
[],
attachments
:
[],
autoClear
:
true
,
...
...
@@ -384,7 +383,7 @@ exports.getTriggered = function (callback, scope) {
};
/**
*
Register
an group of actions by id.
*
Add
an group of actions by id.
*
* @param [ String ] id The Id of the group.
* @param [ Array] actions The action config settings.
...
...
@@ -393,10 +392,35 @@ exports.getTriggered = function (callback, scope) {
*
* @return [ Void ]
*/
exports
.
addAction
Group
=
function
(
id
,
actions
,
callback
,
scope
)
{
exports
.
addAction
s
=
function
(
id
,
actions
,
callback
,
scope
)
{
var
config
=
{
actionGroupId
:
id
,
actions
:
actions
};
this
.
_exec
(
'actions'
,
[
1
,
config
],
callback
,
scope
);
};
this
.
_exec
(
'actions'
,
config
,
callback
,
scope
);
/**
* Remove an group of actions by id.
*
* @param [ String ] id The Id of the group.
* @param [ Function ] callback The function to be exec as the callback.
* @param [ Object ] scope The callback function's scope.
*
* @return [ Void ]
*/
exports
.
removeActions
=
function
(
id
,
callback
,
scope
)
{
this
.
_exec
(
'actions'
,
[
-
1
,
id
],
callback
,
scope
);
};
/**
* Check if a group of actions is defined.
*
* @param [ String ] id The Id of the group.
* @param [ Function ] callback The function to be exec as the callback.
* @param [ Object ] scope The callback function's scope.
*
* @return [ Void ]
*/
exports
.
hasActions
=
function
(
id
,
callback
,
scope
)
{
this
.
_exec
(
'actions'
,
[
0
,
id
],
callback
,
scope
);
};
/**
...
...
@@ -651,8 +675,8 @@ exports._convertPriority = function (options) {
exports
.
_convertActions
=
function
(
options
)
{
var
actions
=
[];
if
(
!
options
.
actions
)
return
null
;
if
(
!
options
.
actions
||
typeof
options
.
actions
===
'string'
)
return
options
;
for
(
var
i
=
0
,
len
=
options
.
actions
.
length
;
i
<
len
;
i
++
)
{
var
action
=
options
.
actions
[
i
];
...
...
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