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
c8ecc570
Commit
c8ecc570
authored
Sep 05, 2017
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Readded support for update() for iOS
parent
03da779a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
120 additions
and
125 deletions
+120
-125
APPLocalNotification.h
src/ios/APPLocalNotification.h
+2
-2
APPLocalNotification.m
src/ios/APPLocalNotification.m
+61
-72
UNNotificationRequest+APPLocalNotification.h
src/ios/UNNotificationRequest+APPLocalNotification.h
+2
-0
UNNotificationRequest+APPLocalNotification.m
src/ios/UNNotificationRequest+APPLocalNotification.m
+10
-0
local-notification-core.js
www/local-notification-core.js
+32
-35
local-notification.js
www/local-notification.js
+13
-16
No files found.
src/ios/APPLocalNotification.h
View file @
c8ecc570
...
...
@@ -40,8 +40,8 @@
// Schedule notifications
-
(
void
)
schedule
:(
CDVInvokedUrlCommand
*
)
command
;
//
//
Update set of notifications
//
- (void) update:(CDVInvokedUrlCommand*)command;
// Update set of notifications
-
(
void
)
update
:(
CDVInvokedUrlCommand
*
)
command
;
// Clear notifications by id
-
(
void
)
clear
:(
CDVInvokedUrlCommand
*
)
command
;
// Clear all notifications
...
...
src/ios/APPLocalNotification.m
View file @
c8ecc570
...
...
@@ -104,60 +104,36 @@
}];
}
///**
// * Update a set of notifications.
// *
// * @param properties
// * A dict of properties for each notification
// */
//- (void) update:(CDVInvokedUrlCommand*)command
//{
// NSArray* notifications = command.arguments;
//
// [self.commandDelegate runInBackground:^{
// if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")) {
// for (NSDictionary* options in notifications) {
// NSNumber* id = [options objectForKey:@"id"];
// UNNotificationRequest* notification;
//
// notification = [_center getNotificationWithId:id];
//
// if (!notification)
// continue;
//
// // [self updateNotification:[notification copy]
// // withOptions:options];
// //
// // [self fireEvent:@"update" notification:notification];
// //
// // if (notifications.count > 1) {
// // [NSThread sleepForTimeInterval:0.01];
// // }
// }
// } else {
// for (NSDictionary* options in notifications) {
// NSNumber* id = [options objectForKey:@"id"];
// UILocalNotification* notification;
//
// notification = [_app localNotificationWithId:id];
//
// if (!notification)
// continue;
//
// [self updateLocalNotification:[notification copy]
// withOptions:options];
//
// [self fireEvent:@"update" localnotification:notification];
//
// if (notifications.count > 1) {
// [NSThread sleepForTimeInterval:0.01];
// }
// }
// }
//
// [self execCallback:command];
// }];
//}
/**
* Update notifications.
*
* @param [Array<Hash>] properties A list of key-value properties.
*
* @return [ Void ]
*/
-
(
void
)
update
:(
CDVInvokedUrlCommand
*
)
command
{
NSArray
*
notifications
=
command
.
arguments
;
[
self
.
commandDelegate
runInBackground
:
^
{
for
(
NSDictionary
*
options
in
notifications
)
{
NSNumber
*
id
=
[
options
objectForKey
:
@"id"
];
UNNotificationRequest
*
notification
;
notification
=
[
_center
getNotificationWithId
:
id
];
if
(
!
notification
)
continue
;
[
self
updateNotification
:[
notification
copy
]
withOptions
:
options
];
[
self
fireEvent
:
@"update"
notification
:
notification
];
}
[
self
execCallback
:
command
];
}];
}
/**
* Clear notifications by id.
...
...
@@ -476,36 +452,46 @@
/**
* Schedule the local notification.
*
* @param [ APPNotificationContent* ] notification The notification to schedule.
*
* @return [ Void ]
*/
-
(
void
)
scheduleNotification
:
(
APPNotificationContent
*
)
notification
{
__weak
APPLocalNotification
*
weakSelf
=
self
;
UNNotificationRequest
*
request
=
notification
.
request
;
NSString
*
event
=
[
notification
.
request
wasUpdated
]
?
@"update"
:
@"add"
;
[
_center
addNotificationCategory
:
notification
.
category
];
[
_center
addNotificationRequest
:
request
withCompletionHandler
:
^
(
NSError
*
e
)
{
__strong
APPLocalNotification
*
strongSelf
=
weakSelf
;
[
strongSelf
fireEvent
:
@"add"
notification
:
request
];
[
strongSelf
fireEvent
:
event
notification
:
request
];
}];
}
///**
// * Update the local notification.
// */
//- (void) updateNotification:(UILocalNotification*)notification
// withOptions:(NSDictionary*)newOptions
//{APPNotificationRequest*
// NSMutableDictionary* options = [notification.userInfo mutableCopy];
//
// [options addEntriesFromDictionary:newOptions];
// [options setObject:[NSDate date] forKey:@"updatedAt"];
//
//// notification = [[UILocalNotification alloc]
//// initWithOptions:options];
////
//// [self scheduleLocalNotification:notification];
//}
/**
* Update the local notification.
*
* @param [ UNNotificationRequest* ] notification The notification to update.
* @param [ NSDictionary* ] options The options to update.
*
* @return [ Void ]
*/
-
(
void
)
updateNotification
:
(
UNNotificationRequest
*
)
notification
withOptions
:
(
NSDictionary
*
)
newOptions
{
NSMutableDictionary
*
options
=
[
notification
.
content
.
userInfo
mutableCopy
];
[
options
addEntriesFromDictionary
:
newOptions
];
[
options
setObject
:[
NSDate
date
]
forKey
:
@"updatedAt"
];
APPNotificationContent
*
newNotification
=
[[
APPNotificationContent
alloc
]
initWithOptions
:
options
];
[
self
scheduleNotification
:
newNotification
];
}
#pragma mark -
#pragma mark UNUserNotificationCenterDelegate
...
...
@@ -517,7 +503,10 @@
willPresentNotification
:
(
UNNotification
*
)
notification
withCompletionHandler
:
(
void
(
^
)(
UNNotificationPresentationOptions
))
completionHandler
{
[
self
fireEvent
:
@"trigger"
notification
:
notification
.
request
];
if
(
!
[
notification
.
request
wasUpdated
])
{
[
self
fireEvent
:
@"trigger"
notification
:
notification
.
request
];
}
completionHandler
(
UNNotificationPresentationOptionBadge
|
UNNotificationPresentationOptionSound
|
UNNotificationPresentationOptionAlert
);
}
...
...
src/ios/UNNotificationRequest+APPLocalNotification.h
View file @
c8ecc570
...
...
@@ -27,6 +27,8 @@
// 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
;
...
...
src/ios/UNNotificationRequest+APPLocalNotification.m
View file @
c8ecc570
...
...
@@ -65,6 +65,16 @@ static char optionsKey;
}
/**
* If the notification was updated.
*
* @return [ BOOL ]
*/
-
(
BOOL
)
wasUpdated
{
return
[
self
.
content
userInfo
][
@"updatedAt"
]
!=
NULL
;
}
/**
* Encode the user info dict to JSON.
*/
-
(
NSString
*
)
encodeToJSON
...
...
www/local-notification-core.js
View file @
c8ecc570
...
...
@@ -83,41 +83,38 @@ exports.schedule = function (msgs, callback, scope, args) {
}
};
// /**
// * Update existing notifications specified by IDs in options.
// *
// * @param {Object} notifications
// * The notification properties to update
// * @param {Function} callback
// * A function to be called after the notification has been updated
// * @param {Object?} scope
// * The scope for the callback function
// * @param {Object?} args
// * skipPermission:true schedules the notifications immediatly without
// * registering or checking for permission
// */
// exports.update = function (msgs, callback, scope, args) {
// var fn = function(granted) {
// if (!granted) return;
// var notifications = Array.isArray(msgs) ? msgs : [msgs];
// for (var i = 0; i < notifications.length; i++) {
// var notification = notifications[i];
// this.convertProperties(notification);
// }
// this.exec('update', notifications, callback, scope);
// };
// if (args && args.skipPermission) {
// fn.call(this, true);
// } else {
// this.registerPermission(fn, this);
// }
// };
/**
* Schedule notifications.
*
* @param [ Array ] notifications The notifications to schedule.
* @param [ Function ] callback The function to be exec as the callback.
* @param [ Object ] scope The callback function's scope.
* @param [ Object ] args Optional flags how to schedule.
*
* @return [ Void ]
*/
exports
.
update
=
function
(
msgs
,
callback
,
scope
,
args
)
{
var
fn
=
function
(
granted
)
{
if
(
!
granted
)
return
;
var
notifications
=
Array
.
isArray
(
msgs
)
?
msgs
:
[
msgs
];
for
(
var
i
=
0
;
i
<
notifications
.
length
;
i
++
)
{
var
notification
=
notifications
[
i
];
this
.
convertProperties
(
notification
);
}
this
.
exec
(
'update'
,
notifications
,
callback
,
scope
);
};
if
(
args
&&
args
.
skipPermission
)
{
fn
.
call
(
this
,
true
);
}
else
{
this
.
requestPermission
(
fn
,
this
);
}
};
/**
* Clear the specified notifications by id.
...
...
www/local-notification.js
View file @
c8ecc570
...
...
@@ -57,22 +57,19 @@ exports.schedule = function (notifications, callback, scope, args) {
this
.
core
.
schedule
(
notifications
,
callback
,
scope
,
args
);
};
// /**
// * Update existing notifications specified by IDs in options.
// *
// * @param {Object} notifications
// * The notification properties to update
// * @param {Function} callback
// * A function to be called after the notification has been updated
// * @param {Object?} scope
// * The scope for the callback function
// * @param {Object?} args
// * skipPermission:true schedules the notifications immediatly without
// * registering or checking for permission
// */
// exports.update = function (notifications, callback, scope, args) {
// this.core.update(notifications, callback, scope, args);
// };
/**
* Update notifications.
*
* @param [ Array ] notifications The notifications to schedule.
* @param [ Function ] callback The function to be exec as the callback.
* @param [ Object ] scope The callback function's scope.
* @param [ Object ] args Optional flags how to schedule.
*
* @return [ Void ]
*/
exports
.
update
=
function
(
notifications
,
callback
,
scope
,
args
)
{
this
.
core
.
update
(
notifications
,
callback
,
scope
,
args
);
};
/**
* Clear the specified notifications by id.
...
...
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