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