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
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
252 additions
and
97 deletions
+252
-97
LocalNotification.java
src/android/LocalNotification.java
+52
-15
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
+2
-2
APPLocalNotification.m
src/ios/APPLocalNotification.m
+51
-20
APPNotificationContent.m
src/ios/APPNotificationContent.m
+1
-1
APPNotificationOptions.h
src/ios/APPNotificationOptions.h
+14
-14
APPNotificationOptions.m
src/ios/APPNotificationOptions.m
+7
-5
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 {
...
@@ -131,17 +131,16 @@ public class LocalNotification extends CordovaPlugin {
if
(
action
.
equals
(
"ready"
))
{
if
(
action
.
equals
(
"ready"
))
{
deviceready
();
deviceready
();
}
else
}
else
if
(
action
.
equals
IgnoreCase
(
"check"
))
{
if
(
action
.
equals
(
"check"
))
{
check
(
command
);
check
(
command
);
}
else
}
else
if
(
action
.
equals
IgnoreCase
(
"request"
))
{
if
(
action
.
equals
(
"request"
))
{
request
(
command
);
request
(
command
);
}
else
}
else
if
(
action
.
equalsIgnoreCase
(
"actions"
))
{
if
(
action
.
equals
(
"actions"
))
{
actions
(
args
.
optJSONObject
(
0
));
actions
(
args
,
command
);
command
.
success
();
}
else
}
else
if
(
action
.
equals
IgnoreCase
(
"schedule"
))
{
if
(
action
.
equals
(
"schedule"
))
{
schedule
(
args
);
schedule
(
args
);
check
(
command
);
check
(
command
);
}
else
}
else
...
@@ -227,10 +226,8 @@ public class LocalNotification extends CordovaPlugin {
...
@@ -227,10 +226,8 @@ public class LocalNotification extends CordovaPlugin {
* JavaScript.
* JavaScript.
*/
*/
private
void
check
(
CallbackContext
command
)
{
private
void
check
(
CallbackContext
command
)
{
boolean
allowed
=
getNotMgr
().
hasPermission
();
boolean
allowed
=
getNotMgr
().
hasPermission
();
PluginResult
result
=
new
PluginResult
(
PluginResult
.
Status
.
OK
,
allowed
);
success
(
command
,
allowed
);
command
.
sendPluginResult
(
result
);
}
}
/**
/**
...
@@ -246,13 +243,41 @@ public class LocalNotification extends CordovaPlugin {
...
@@ -246,13 +243,41 @@ public class LocalNotification extends CordovaPlugin {
/**
/**
* Register action group.
* 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
)
{
private
void
actions
(
JSONArray
args
,
CallbackContext
command
)
{
ActionGroup
group
=
ActionGroup
.
parse
(
cordova
.
getActivity
(),
args
);
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
();
if
(
group
!=
null
)
{
break
;
ActionGroup
.
register
(
group
);
case
0
:
id
=
args
.
optString
(
1
);
found
=
ActionGroup
.
isRegistered
(
id
);
success
(
command
,
found
);
break
;
}
}
}
}
...
@@ -485,6 +510,18 @@ public class LocalNotification extends CordovaPlugin {
...
@@ -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.
* Fire given event on JS side. Does inform all event listeners.
*
*
* @param event The event name.
* @param event The event name.
...
...
src/android/notification/Options.java
View file @
5759483e
...
@@ -596,24 +596,26 @@ public final class Options {
...
@@ -596,24 +596,26 @@ public final class Options {
* Gets the list of actions to display.
* Gets the list of actions to display.
*/
*/
Action
[]
getActions
()
{
Action
[]
getActions
()
{
String
groupId
=
options
.
optString
(
"actionGroupId"
,
null
);
Object
value
=
options
.
opt
(
"actions"
);
JSONArray
actions
=
options
.
optJSONArray
(
"actions"
);
String
groupId
=
null
;
JSONArray
actions
=
null
;
ActionGroup
group
=
null
;
ActionGroup
group
=
null
;
if
(
actions
!=
null
&&
actions
.
length
()
>
0
)
{
if
(
value
instanceof
String
)
{
group
=
ActionGroup
.
parse
(
context
,
options
);
groupId
=
(
String
)
value
;
}
else
if
(
value
instanceof
JSONArray
)
{
actions
=
(
JSONArray
)
value
;
}
}
if
(
group
==
null
&&
group
Id
!=
null
)
{
if
(
groupId
!=
null
)
{
group
=
ActionGroup
.
lookup
(
groupId
);
group
=
ActionGroup
.
lookup
(
groupId
);
}
else
if
(
actions
!=
null
&&
actions
.
length
()
>
0
)
{
group
=
ActionGroup
.
parse
(
context
,
options
);
}
}
if
(
group
!=
null
)
{
return
(
group
!=
null
)
?
group
.
getActions
()
:
null
;
ActionGroup
.
register
(
group
);
return
group
.
getActions
();
}
return
null
;
}
}
/**
/**
...
...
src/android/notification/action/ActionGroup.java
View file @
5759483e
...
@@ -73,6 +73,24 @@ public final class ActionGroup {
...
@@ -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.
* Creates an action group by parsing the specified action specs.
*
*
* @param spec The action group spec containing the id and list of actions.
* @param spec The action group spec containing the id and list of actions.
...
...
src/android/notification/util/AssetUtil.java
View file @
5759483e
...
@@ -106,7 +106,7 @@ public final class AssetUtil {
...
@@ -106,7 +106,7 @@ public final class AssetUtil {
*/
*/
private
Uri
getUriFromPath
(
String
path
)
{
private
Uri
getUriFromPath
(
String
path
)
{
String
absPath
=
path
.
replaceFirst
(
"file://"
,
""
)
String
absPath
=
path
.
replaceFirst
(
"file://"
,
""
)
.
replaceFirst
(
"\\?.*$"
,
""
);
.
replaceFirst
(
"\\?.*$"
,
""
);
File
file
=
new
File
(
absPath
);
File
file
=
new
File
(
absPath
);
if
(!
file
.
exists
())
{
if
(!
file
.
exists
())
{
...
@@ -126,7 +126,7 @@ public final class AssetUtil {
...
@@ -126,7 +126,7 @@ public final class AssetUtil {
*/
*/
private
Uri
getUriFromAsset
(
String
path
)
{
private
Uri
getUriFromAsset
(
String
path
)
{
String
resPath
=
path
.
replaceFirst
(
"file:/"
,
"www"
)
String
resPath
=
path
.
replaceFirst
(
"file:/"
,
"www"
)
.
replaceFirst
(
"\\?.*$"
,
""
);
.
replaceFirst
(
"\\?.*$"
,
""
);
String
fileName
=
resPath
.
substring
(
resPath
.
lastIndexOf
(
'/'
)
+
1
);
String
fileName
=
resPath
.
substring
(
resPath
.
lastIndexOf
(
'/'
)
+
1
);
File
file
=
getTmpFile
(
fileName
);
File
file
=
getTmpFile
(
fileName
);
...
...
src/ios/APPLocalNotification.m
View file @
5759483e
...
@@ -176,7 +176,7 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
...
@@ -176,7 +176,7 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
-
(
void
)
clearAll
:(
CDVInvokedUrlCommand
*
)
command
-
(
void
)
clearAll
:(
CDVInvokedUrlCommand
*
)
command
{
{
[
self
.
commandDelegate
runInBackground
:
^
{
[
self
.
commandDelegate
runInBackground
:
^
{
[
_center
clear
All
Notifications
];
[
_center
clearNotifications
];
[
self
clearApplicationIconBadgeNumber
];
[
self
clearApplicationIconBadgeNumber
];
[
self
fireEvent
:
@"clearall"
];
[
self
fireEvent
:
@"clearall"
];
[
self
execCallback
:
command
];
[
self
execCallback
:
command
];
...
@@ -217,7 +217,7 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
...
@@ -217,7 +217,7 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
-
(
void
)
cancelAll
:(
CDVInvokedUrlCommand
*
)
command
-
(
void
)
cancelAll
:(
CDVInvokedUrlCommand
*
)
command
{
{
[
self
.
commandDelegate
runInBackground
:
^
{
[
self
.
commandDelegate
runInBackground
:
^
{
[
_center
cancel
All
Notifications
];
[
_center
cancelNotifications
];
[
self
clearApplicationIconBadgeNumber
];
[
self
clearApplicationIconBadgeNumber
];
[
self
fireEvent
:
@"cancelall"
];
[
self
fireEvent
:
@"cancelall"
];
[
self
execCallback
:
command
];
[
self
execCallback
:
command
];
...
@@ -408,15 +408,10 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
...
@@ -408,15 +408,10 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
{
{
[
_center
getNotificationSettingsWithCompletionHandler
:
^
(
UNNotificationSettings
*
settings
)
{
[
_center
getNotificationSettingsWithCompletionHandler
:
^
(
UNNotificationSettings
*
settings
)
{
BOOL
authorized
=
settings
.
authorizationStatus
==
UNAuthorizationStatusAuthorized
;
BOOL
authorized
=
settings
.
authorizationStatus
==
UNAuthorizationStatusAuthorized
;
BOOL
enabled
=
settings
.
notificationCenterSetting
==
UNNotificationSettingEnabled
;
BOOL
enabled
=
settings
.
notificationCenterSetting
==
UNNotificationSettingEnabled
;
BOOL
permitted
=
authorized
&&
enabled
;
BOOL
permitted
=
authorized
&&
enabled
;
CDVPluginResult
*
result
;
[
self
execCallback
:
command
arg
:
permitted
];
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsBool
:
permitted
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
command
.
callbackId
];
}];
}];
}
}
...
@@ -443,14 +438,37 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
...
@@ -443,14 +438,37 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
-
(
void
)
actions
:
(
CDVInvokedUrlCommand
*
)
command
-
(
void
)
actions
:
(
CDVInvokedUrlCommand
*
)
command
{
{
[
self
.
commandDelegate
runInBackground
:
^
{
[
self
.
commandDelegate
runInBackground
:
^
{
NSDictionary
*
options
=
command
.
arguments
[
0
];
int
task
=
[
command
.
arguments
[
0
]
intValue
];
APPNotificationContent
*
notification
;
APPNotificationContent
*
notification
;
NSDictionary
*
options
;
NSString
*
identifier
;
BOOL
found
;
notification
=
[[
APPNotificationContent
alloc
]
switch
(
task
)
{
initWithOptions
:
options
];
case
1
:
options
=
command
.
arguments
[
1
];
notification
=
[[
APPNotificationContent
alloc
]
initWithOptions
:
options
];
[
_center
addNotificationCategory
:
notification
.
category
];
[
_center
addActionGroup
:
notification
.
category
];
[
self
execCallback
:
command
];
[
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
;
}
}];
}];
}
}
...
@@ -466,11 +484,9 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
...
@@ -466,11 +484,9 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
*/
*/
-
(
void
)
scheduleNotification
:
(
APPNotificationContent
*
)
notification
-
(
void
)
scheduleNotification
:
(
APPNotificationContent
*
)
notification
{
{
__weak
APPLocalNotification
*
weakSelf
=
self
;
__weak
APPLocalNotification
*
weakSelf
=
self
;
UNNotificationRequest
*
request
=
notification
.
request
;
UNNotificationRequest
*
request
=
notification
.
request
;
NSString
*
event
=
[
request
wasUpdated
]
?
@"update"
:
@"add"
;
NSString
*
event
=
[
request
wasUpdated
]
?
@"update"
:
@"add"
;
[
_center
addNotificationCategory
:
notification
.
category
];
[
_center
addNotificationRequest
:
request
withCompletionHandler
:
^
(
NSError
*
e
)
{
[
_center
addNotificationRequest
:
request
withCompletionHandler
:
^
(
NSError
*
e
)
{
__strong
APPLocalNotification
*
strongSelf
=
weakSelf
;
__strong
APPLocalNotification
*
strongSelf
=
weakSelf
;
...
@@ -642,6 +658,21 @@ UNNotificationPresentationOptions const OptionAlert = UNNotificationPresentation
...
@@ -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.
* Fire general event.
*
*
* @param [ NSString* ] event The name of the event to fire.
* @param [ NSString* ] event The name of the event to fire.
...
...
src/ios/APPNotificationContent.m
View file @
5759483e
...
@@ -64,7 +64,7 @@ static char optionsKey;
...
@@ -64,7 +64,7 @@ static char optionsKey;
self
.
sound
=
options
.
sound
;
self
.
sound
=
options
.
sound
;
self
.
badge
=
options
.
badge
;
self
.
badge
=
options
.
badge
;
self
.
attachments
=
options
.
attachments
;
self
.
attachments
=
options
.
attachments
;
self
.
categoryIdentifier
=
options
.
category
Id
;
self
.
categoryIdentifier
=
options
.
actionGroup
Id
;
}
}
#pragma mark -
#pragma mark -
...
...
src/ios/APPNotificationOptions.h
View file @
5759483e
...
@@ -23,21 +23,21 @@
...
@@ -23,21 +23,21 @@
@interface
APPNotificationOptions
:
NSObject
@interface
APPNotificationOptions
:
NSObject
@property
(
readonly
,
getter
=
id
)
NSNumber
*
id
;
@property
(
readonly
,
getter
=
id
)
NSNumber
*
id
;
@property
(
readonly
,
getter
=
identifier
)
NSString
*
identifier
;
@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
=
title
)
NSString
*
title
;
@property
(
readonly
,
getter
=
subtitle
)
NSString
*
subtitle
;
@property
(
readonly
,
getter
=
subtitle
)
NSString
*
subtitle
;
@property
(
readonly
,
getter
=
badge
)
NSNumber
*
badge
;
@property
(
readonly
,
getter
=
badge
)
NSNumber
*
badge
;
@property
(
readonly
,
getter
=
text
)
NSString
*
text
;
@property
(
readonly
,
getter
=
text
)
NSString
*
text
;
@property
(
readonly
,
getter
=
silent
)
BOOL
silent
;
@property
(
readonly
,
getter
=
silent
)
BOOL
silent
;
@property
(
readonly
,
getter
=
priority
)
int
priority
;
@property
(
readonly
,
getter
=
priority
)
int
priority
;
@property
(
readonly
,
getter
=
sound
)
UNNotificationSound
*
sound
;
@property
(
readonly
,
getter
=
sound
)
UNNotificationSound
*
sound
;
@property
(
readonly
,
getter
=
userInfo
)
NSDictionary
*
userInfo
;
@property
(
readonly
,
getter
=
userInfo
)
NSDictionary
*
userInfo
;
@property
(
readonly
,
getter
=
actions
)
NSArray
<
UNNotificationAction
*>
*
actions
;
@property
(
readonly
,
getter
=
actions
)
NSArray
<
UNNotificationAction
*>*
actions
;
@property
(
readonly
,
getter
=
attachments
)
NSArray
<
UNNotificationAttachment
*>
*
attachments
;
@property
(
readonly
,
getter
=
attachments
)
NSArray
<
UNNotificationAttachment
*>*
attachments
;
-
(
id
)
initWithDict
:(
NSDictionary
*
)
dict
;
-
(
id
)
initWithDict
:(
NSDictionary
*
)
dict
;
-
(
UNNotificationTrigger
*
)
trigger
;
-
(
UNNotificationTrigger
*
)
trigger
;
@end
@end
src/ios/APPNotificationOptions.m
View file @
5759483e
...
@@ -51,12 +51,9 @@ static NSInteger WEEKDAYS[8] = { 0, 2, 3, 4, 5, 6, 7, 1 };
...
@@ -51,12 +51,9 @@ static NSInteger WEEKDAYS[8] = { 0, 2, 3, 4, 5, 6, 7, 1 };
*/
*/
-
(
id
)
initWithDict
:(
NSDictionary
*
)
dictionary
-
(
id
)
initWithDict
:(
NSDictionary
*
)
dictionary
{
{
self
=
[
self
init
];
self
=
[
self
init
];
self
.
dict
=
dictionary
;
self
.
dict
=
dictionary
;
[
self
actions
];
return
self
;
return
self
;
}
}
...
@@ -154,8 +151,13 @@ static NSInteger WEEKDAYS[8] = { 0, 2, 3, 4, 5, 6, 7, 1 };
...
@@ -154,8 +151,13 @@ static NSInteger WEEKDAYS[8] = { 0, 2, 3, 4, 5, 6, 7, 1 };
*
*
* @return [ NSString* ]
* @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"
];
NSString
*
value
=
[
dict
objectForKey
:
@"actionGroupId"
];
return
value
.
length
?
value
:
kAPPGeneralCategory
;
return
value
.
length
?
value
:
kAPPGeneralCategory
;
...
...
src/ios/UNNotificationRequest+APPLocalNotification.h
View file @
5759483e
...
@@ -25,11 +25,8 @@
...
@@ -25,11 +25,8 @@
@interface
UNNotificationRequest
(
APPLocalNotification
)
@interface
UNNotificationRequest
(
APPLocalNotification
)
// The options provided by the plug-in
-
(
APPNotificationOptions
*
)
options
;
-
(
APPNotificationOptions
*
)
options
;
// If the notification was updated
-
(
BOOL
)
wasUpdated
;
-
(
BOOL
)
wasUpdated
;
// Encode the user info dict to JSON
-
(
NSString
*
)
encodeToJSON
;
-
(
NSString
*
)
encodeToJSON
;
@end
@end
src/ios/UNUserNotificationCenter+APPLocalNotification.h
View file @
5759483e
...
@@ -37,34 +37,24 @@ typedef NS_ENUM(NSUInteger, APPNotificationType) {
...
@@ -37,34 +37,24 @@ typedef NS_ENUM(NSUInteger, APPNotificationType) {
@property
(
readonly
,
getter
=
getNotifications
)
NSArray
*
localNotifications
;
@property
(
readonly
,
getter
=
getNotifications
)
NSArray
*
localNotifications
;
@property
(
readonly
,
getter
=
getNotificationIds
)
NSArray
*
localNotificationIds
;
@property
(
readonly
,
getter
=
getNotificationIds
)
NSArray
*
localNotificationIds
;
// Register general notification category to listen for dismiss actions
-
(
void
)
registerGeneralNotificationCategory
;
-
(
void
)
registerGeneralNotificationCategory
;
// Add the specified category to the list of categories
-
(
void
)
addActionGroup
:(
UNNotificationCategory
*
)
category
;
-
(
void
)
addNotificationCategory
:(
UNNotificationCategory
*
)
category
;
-
(
void
)
removeActionGroup
:(
NSString
*
)
identifier
;
-
(
BOOL
)
hasActionGroup
:(
NSString
*
)
identifier
;
// List of all notification IDs from given type
-
(
NSArray
*
)
getNotificationIdsByType
:(
APPNotificationType
)
type
;
-
(
NSArray
*
)
getNotificationIdsByType
:(
APPNotificationType
)
type
;
// Find notification by ID
-
(
UNNotificationRequest
*
)
getNotificationWithId
:(
NSNumber
*
)
id
;
-
(
UNNotificationRequest
*
)
getNotificationWithId
:(
NSNumber
*
)
id
;
// Find notification type by ID
-
(
APPNotificationType
)
getTypeOfNotificationWithId
:(
NSNumber
*
)
id
;
-
(
APPNotificationType
)
getTypeOfNotificationWithId
:(
NSNumber
*
)
id
;
// Property list from all local notifications
-
(
NSArray
*
)
getNotificationOptions
;
-
(
NSArray
*
)
getNotificationOptions
;
// Property list from given local notifications
-
(
NSArray
*
)
getNotificationOptionsById
:(
NSArray
*
)
ids
;
-
(
NSArray
*
)
getNotificationOptionsById
:(
NSArray
*
)
ids
;
// Property list from all local notifications with type constraint
-
(
NSArray
*
)
getNotificationOptionsByType
:(
APPNotificationType
)
type
;
-
(
NSArray
*
)
getNotificationOptionsByType
:(
APPNotificationType
)
type
;
// Clear specified notfication
-
(
void
)
clearNotification
:(
UNNotificationRequest
*
)
notification
;
-
(
void
)
clearNotification
:(
UNNotificationRequest
*
)
notification
;
// Clear all notfications
-
(
void
)
clearNotifications
;
-
(
void
)
clearAllNotifications
;
// Cancel specified notfication
-
(
void
)
cancelNotification
:(
UNNotificationRequest
*
)
notification
;
-
(
void
)
cancelNotification
:(
UNNotificationRequest
*
)
notification
;
// Cancel all notfications
-
(
void
)
cancelNotifications
;
-
(
void
)
cancelAllNotifications
;
@end
@end
src/ios/UNUserNotificationCenter+APPLocalNotification.m
View file @
5759483e
...
@@ -56,7 +56,7 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
...
@@ -56,7 +56,7 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
*
*
* @return [ Void ]
* @return [ Void ]
*/
*/
-
(
void
)
add
NotificationCategory
:
(
UNNotificationCategory
*
)
category
-
(
void
)
add
ActionGroup
:
(
UNNotificationCategory
*
)
category
{
{
if
(
!
category
)
if
(
!
category
)
return
;
return
;
...
@@ -64,7 +64,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
...
@@ -64,7 +64,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
[
self
getNotificationCategoriesWithCompletionHandler
:
^
(
NSSet
<
UNNotificationCategory
*>
*
set
)
{
[
self
getNotificationCategoriesWithCompletionHandler
:
^
(
NSSet
<
UNNotificationCategory
*>
*
set
)
{
NSMutableSet
*
categories
=
[
NSMutableSet
setWithSet
:
set
];
NSMutableSet
*
categories
=
[
NSMutableSet
setWithSet
:
set
];
for
(
UNNotificationCategory
*
item
in
categories
)
{
for
(
UNNotificationCategory
*
item
in
categories
)
{
if
([
category
.
identifier
isEqualToString
:
item
.
identifier
])
{
if
([
category
.
identifier
isEqualToString
:
item
.
identifier
])
{
[
categories
removeObject
:
item
];
[
categories
removeObject
:
item
];
break
;
break
;
...
@@ -76,6 +77,58 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
...
@@ -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 -
#pragma mark LocalNotifications
#pragma mark LocalNotifications
...
@@ -101,7 +154,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
...
@@ -101,7 +154,8 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
dispatch_semaphore_t
sema
=
dispatch_semaphore_create
(
0
);
dispatch_semaphore_t
sema
=
dispatch_semaphore_create
(
0
);
[
self
getDeliveredNotificationsWithCompletionHandler
:
^
(
NSArray
<
UNNotification
*>
*
delivered
)
{
[
self
getDeliveredNotificationsWithCompletionHandler
:
^
(
NSArray
<
UNNotification
*>
*
delivered
)
{
for
(
UNNotification
*
notification
in
delivered
)
{
for
(
UNNotification
*
notification
in
delivered
)
{
[
notifications
addObject
:
notification
.
request
];
[
notifications
addObject
:
notification
.
request
];
}
}
dispatch_semaphore_signal
(
sema
);
dispatch_semaphore_signal
(
sema
);
...
@@ -276,7 +330,7 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
...
@@ -276,7 +330,7 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/*
/*
* Clear all notfications.
* Clear all notfications.
*/
*/
-
(
void
)
clear
All
Notifications
-
(
void
)
clearNotifications
{
{
[
self
removeAllDeliveredNotifications
];
[
self
removeAllDeliveredNotifications
];
}
}
...
@@ -298,7 +352,7 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
...
@@ -298,7 +352,7 @@ NSString * const kAPPGeneralCategory = @"GENERAL";
/*
/*
* Cancel all notfications.
* Cancel all notfications.
*/
*/
-
(
void
)
cancel
All
Notifications
-
(
void
)
cancelNotifications
{
{
[
self
removeAllPendingNotificationRequests
];
[
self
removeAllPendingNotificationRequests
];
[
self
removeAllDeliveredNotifications
];
[
self
removeAllDeliveredNotifications
];
...
...
www/local-notification.js
View file @
5759483e
...
@@ -24,7 +24,6 @@ var exec = require('cordova/exec'),
...
@@ -24,7 +24,6 @@ var exec = require('cordova/exec'),
// Defaults
// Defaults
exports
.
_defaults
=
{
exports
.
_defaults
=
{
actionGroupId
:
null
,
actions
:
[],
actions
:
[],
attachments
:
[],
attachments
:
[],
autoClear
:
true
,
autoClear
:
true
,
...
@@ -384,7 +383,7 @@ exports.getTriggered = function (callback, scope) {
...
@@ -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 [ String ] id The Id of the group.
* @param [ Array] actions The action config settings.
* @param [ Array] actions The action config settings.
...
@@ -393,10 +392,35 @@ exports.getTriggered = function (callback, scope) {
...
@@ -393,10 +392,35 @@ exports.getTriggered = function (callback, scope) {
*
*
* @return [ Void ]
* @return [ Void ]
*/
*/
exports
.
addAction
Group
=
function
(
id
,
actions
,
callback
,
scope
)
{
exports
.
addAction
s
=
function
(
id
,
actions
,
callback
,
scope
)
{
var
config
=
{
actionGroupId
:
id
,
actions
:
actions
};
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) {
...
@@ -651,8 +675,8 @@ exports._convertPriority = function (options) {
exports
.
_convertActions
=
function
(
options
)
{
exports
.
_convertActions
=
function
(
options
)
{
var
actions
=
[];
var
actions
=
[];
if
(
!
options
.
actions
)
if
(
!
options
.
actions
||
typeof
options
.
actions
===
'string'
)
return
null
;
return
options
;
for
(
var
i
=
0
,
len
=
options
.
actions
.
length
;
i
<
len
;
i
++
)
{
for
(
var
i
=
0
,
len
=
options
.
actions
.
length
;
i
<
len
;
i
++
)
{
var
action
=
options
.
actions
[
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