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
1694a815
Commit
1694a815
authored
Jan 12, 2015
by
PKnittel
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/katzer/cordova-plugin-local-notifications
parents
2d2ce205
9258d909
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
128 additions
and
61 deletions
+128
-61
plugin.xml
plugin.xml
+3
-3
APPLocalNotification.h
src/ios/APPLocalNotification.h
+2
-0
APPLocalNotification.m
src/ios/APPLocalNotification.m
+58
-16
APPLocalNotificationOptions.h
src/ios/APPLocalNotificationOptions.h
+0
-2
APPLocalNotificationOptions.m
src/ios/APPLocalNotificationOptions.m
+0
-22
UILocalNotification+APPLocalNotification.h
src/ios/UILocalNotification+APPLocalNotification.h
+4
-0
UILocalNotification+APPLocalNotification.m
src/ios/UILocalNotification+APPLocalNotification.m
+46
-3
local-notification.js
www/local-notification.js
+15
-15
No files found.
plugin.xml
View file @
1694a815
...
@@ -103,7 +103,7 @@
...
@@ -103,7 +103,7 @@
<source-file
src=
"src/android/Restore.java"
target-dir=
"src/de/appplant/cordova/plugin/localnotification"
/>
<source-file
src=
"src/android/Restore.java"
target-dir=
"src/de/appplant/cordova/plugin/localnotification"
/>
<source-file
src=
"src/android/ReceiverActivity.java"
target-dir=
"src/de/appplant/cordova/plugin/localnotification"
/>
<source-file
src=
"src/android/ReceiverActivity.java"
target-dir=
"src/de/appplant/cordova/plugin/localnotification"
/>
<source-file
src=
"src/android/DeleteIntentReceiver.java"
target-dir=
"src/de/appplant/cordova/plugin/localnotification"
/>
<source-file
src=
"src/android/DeleteIntentReceiver.java"
target-dir=
"src/de/appplant/cordova/plugin/localnotification"
/>
<source-file
src=
"src/android/notification/Options.java"
target-dir=
"src/de/appplant/cordova/plugin/notification"
/>
<source-file
src=
"src/android/notification/Options.java"
target-dir=
"src/de/appplant/cordova/plugin/notification"
/>
<source-file
src=
"src/android/notification/Asset.java"
target-dir=
"src/de/appplant/cordova/plugin/notification"
/>
<source-file
src=
"src/android/notification/Asset.java"
target-dir=
"src/de/appplant/cordova/plugin/notification"
/>
<source-file
src=
"src/android/notification/Manager.java"
target-dir=
"src/de/appplant/cordova/plugin/notification"
/>
<source-file
src=
"src/android/notification/Manager.java"
target-dir=
"src/de/appplant/cordova/plugin/notification"
/>
...
@@ -112,7 +112,7 @@
...
@@ -112,7 +112,7 @@
</platform>
</platform>
<!-- wp8 -->
<!-- wp8 -->
<platform
name=
"wp8"
>
<!--
<platform name="wp8">
<config-file target="config.xml" parent="/*">
<config-file target="config.xml" parent="/*">
<feature name="LocalNotification">
<feature name="LocalNotification">
<param name="wp-package" value="LocalNotification"/>
<param name="wp-package" value="LocalNotification"/>
...
@@ -121,6 +121,6 @@
...
@@ -121,6 +121,6 @@
<source-file src="src/wp8/LocalNotification.cs" />
<source-file src="src/wp8/LocalNotification.cs" />
<source-file src="src/wp8/Options.cs" />
<source-file src="src/wp8/Options.cs" />
</platform>
</platform>
-->
</plugin>
</plugin>
src/ios/APPLocalNotification.h
View file @
1694a815
...
@@ -28,6 +28,8 @@
...
@@ -28,6 +28,8 @@
-
(
void
)
deviceready
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
deviceready
:(
CDVInvokedUrlCommand
*
)
command
;
// Schedule a new notification
// Schedule a new notification
-
(
void
)
add
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
add
:(
CDVInvokedUrlCommand
*
)
command
;
// Update a notification
-
(
void
)
update
:(
CDVInvokedUrlCommand
*
)
command
;
// Cancel a given notification
// Cancel a given notification
-
(
void
)
cancel
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
cancel
:(
CDVInvokedUrlCommand
*
)
command
;
// Cancel all currently scheduled notifications
// Cancel all currently scheduled notifications
...
...
src/ios/APPLocalNotification.m
View file @
1694a815
...
@@ -72,7 +72,7 @@
...
@@ -72,7 +72,7 @@
NSArray
*
notifications
=
command
.
arguments
;
NSArray
*
notifications
=
command
.
arguments
;
[
self
.
commandDelegate
runInBackground
:
^
{
[
self
.
commandDelegate
runInBackground
:
^
{
for
(
NS
Mutable
Dictionary
*
options
in
notifications
)
{
for
(
NSDictionary
*
options
in
notifications
)
{
UILocalNotification
*
notification
;
UILocalNotification
*
notification
;
notification
=
[[
UILocalNotification
alloc
]
notification
=
[[
UILocalNotification
alloc
]
...
@@ -91,6 +91,39 @@
...
@@ -91,6 +91,39 @@
}
}
/**
/**
* 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
:
^
{
for
(
NSDictionary
*
options
in
notifications
)
{
NSString
*
id
=
[
options
objectForKey
:
@"id"
];
UILocalNotification
*
notification
;
notification
=
[[
UIApplication
sharedApplication
]
scheduledLocalNotificationWithId
:
id
];
if
(
!
notification
)
continue
;
[
self
updateLocalNotification
:[
notification
copy
]
withOptions
:
options
];
if
(
notifications
.
count
>
1
)
{
[
NSThread
sleepForTimeInterval
:
0
.
01
];
}
}
[
self
execCallback
:
command
];
}];
}
/**
* Cancel a set of notifications.
* Cancel a set of notifications.
*
*
* @param ids
* @param ids
...
@@ -336,13 +369,28 @@
...
@@ -336,13 +369,28 @@
}
}
/**
/**
* Update the local notification.
*/
-
(
void
)
updateLocalNotification
:(
UILocalNotification
*
)
notification
withOptions
:(
NSDictionary
*
)
newOptions
{
NSMutableDictionary
*
options
=
[
notification
.
userInfo
mutableCopy
];
[
options
addEntriesFromDictionary
:
newOptions
];
[
options
setObject
:[
NSDate
date
]
forKey
:
@"updatedAt"
];
notification
=
[[
UILocalNotification
alloc
]
initWithOptions
:
options
];
[
self
scheduleLocalNotification
:
notification
];
}
/**
* Cancel the local notification.
* Cancel the local notification.
*/
*/
-
(
void
)
cancelLocalNotification
:(
UILocalNotification
*
)
notification
-
(
void
)
cancelLocalNotification
:(
UILocalNotification
*
)
notification
{
{
if
(
!
notification
)
return
;
[[
UIApplication
sharedApplication
]
[[
UIApplication
sharedApplication
]
cancelLocalNotification
:
notification
];
cancelLocalNotification
:
notification
];
...
@@ -355,15 +403,6 @@
...
@@ -355,15 +403,6 @@
*/
*/
-
(
void
)
cancelAllLocalNotifications
-
(
void
)
cancelAllLocalNotifications
{
{
NSArray
*
notifications
;
notifications
=
[[
UIApplication
sharedApplication
]
scheduledLocalNotifications
];
for
(
UILocalNotification
*
notification
in
notifications
)
{
[
self
cancelLocalNotification
:
notification
];
}
[[
UIApplication
sharedApplication
]
[[
UIApplication
sharedApplication
]
cancelAllLocalNotifications
];
cancelAllLocalNotifications
];
...
@@ -401,7 +440,7 @@
...
@@ -401,7 +440,7 @@
for
(
UILocalNotification
*
notification
in
notifications
)
for
(
UILocalNotification
*
notification
in
notifications
)
{
{
if
(
notification
&&
notification
.
repeatInterval
==
NSCalendarUnitEra
if
(
notification
&&
[
notification
isRepeating
]
&&
notification
.
timeIntervalSinceFireDate
>
seconds
)
&&
notification
.
timeIntervalSinceFireDate
>
seconds
)
{
{
[
self
cancelLocalNotification
:
notification
];
[
self
cancelLocalNotification
:
notification
];
...
@@ -421,8 +460,11 @@
...
@@ -421,8 +460,11 @@
{
{
UILocalNotification
*
notification
=
[
localNotification
object
];
UILocalNotification
*
notification
=
[
localNotification
object
];
if
([
notification
wasUpdated
])
return
;
BOOL
autoCancel
=
notification
.
options
.
autoCancel
;
BOOL
autoCancel
=
notification
.
options
.
autoCancel
;
NSTimeInterval
timeInterval
=
notification
.
timeIntervalSinceFireDate
;
NSTimeInterval
timeInterval
=
[
notification
timeIntervalSinceFireDate
]
;
NSString
*
event
=
(
timeInterval
<=
1
&&
deviceready
)
?
@"trigger"
:
@"click"
;
NSString
*
event
=
(
timeInterval
<=
1
&&
deviceready
)
?
@"trigger"
:
@"click"
;
...
@@ -560,7 +602,7 @@
...
@@ -560,7 +602,7 @@
if
(
notification
)
{
if
(
notification
)
{
NSString
*
id
=
notification
.
options
.
id
;
NSString
*
id
=
notification
.
options
.
id
;
NSString
*
json
=
notification
.
options
.
json
;
NSString
*
json
=
notification
.
options
.
json
;
NSString
*
args
=
[
notification
.
options
encodeToJSON
];
NSString
*
args
=
[
notification
encodeToJSON
];
params
=
[
NSString
stringWithFormat
:
params
=
[
NSString
stringWithFormat
:
@"
\"
%@
\"
,
\"
%@
\"
,
\\
'%@
\\
',JSON.parse(
\\
'%@
\\
')"
,
@"
\"
%@
\"
,
\"
%@
\"
,
\\
'%@
\\
',JSON.parse(
\\
'%@
\\
')"
,
...
...
src/ios/APPLocalNotificationOptions.h
View file @
1694a815
...
@@ -33,8 +33,6 @@
...
@@ -33,8 +33,6 @@
@property
(
readonly
,
getter
=
repeatInterval
)
NSCalendarUnit
repeatInterval
;
@property
(
readonly
,
getter
=
repeatInterval
)
NSCalendarUnit
repeatInterval
;
@property
(
readonly
,
getter
=
userInfo
)
NSDictionary
*
userInfo
;
@property
(
readonly
,
getter
=
userInfo
)
NSDictionary
*
userInfo
;
// Encode the user info dict to JSON
-
(
NSString
*
)
encodeToJSON
;
// If it's a repeating notification
// If it's a repeating notification
-
(
BOOL
)
isRepeating
;
-
(
BOOL
)
isRepeating
;
...
...
src/ios/APPLocalNotificationOptions.m
View file @
1694a815
...
@@ -213,28 +213,6 @@
...
@@ -213,28 +213,6 @@
}
}
/**
/**
* Encode the user info dict to JSON.
*/
-
(
NSString
*
)
encodeToJSON
{
NSString
*
json
;
NSData
*
data
;
NSMutableDictionary
*
obj
=
[
dict
mutableCopy
];
[
obj
removeObjectForKey
:
@"json"
];
data
=
[
NSJSONSerialization
dataWithJSONObject
:
obj
options
:
NSJSONWritingPrettyPrinted
error
:
Nil
];
json
=
[[
NSString
alloc
]
initWithData
:
data
encoding
:
NSUTF8StringEncoding
];
return
[
json
stringByReplacingOccurrencesOfString
:
@"
\n
"
withString
:
@""
];
}
/**
* If it's a repeating notification.
* If it's a repeating notification.
*/
*/
-
(
BOOL
)
isRepeating
-
(
BOOL
)
isRepeating
...
...
src/ios/UILocalNotification+APPLocalNotification.h
View file @
1694a815
...
@@ -33,7 +33,11 @@
...
@@ -33,7 +33,11 @@
-
(
BOOL
)
wasInThePast
;
-
(
BOOL
)
wasInThePast
;
// If the notification was already triggered
// If the notification was already triggered
-
(
BOOL
)
wasTriggered
;
-
(
BOOL
)
wasTriggered
;
// If the notification was updated
-
(
BOOL
)
wasUpdated
;
// If it's a repeating notification
// If it's a repeating notification
-
(
BOOL
)
isRepeating
;
-
(
BOOL
)
isRepeating
;
// Encode the user info dict to JSON
-
(
NSString
*
)
encodeToJSON
;
@end
@end
src/ios/UILocalNotification+APPLocalNotification.m
View file @
1694a815
...
@@ -28,7 +28,7 @@ static char optionsKey;
...
@@ -28,7 +28,7 @@ static char optionsKey;
@implementation
UILocalNotification
(
APPLocalNotification
)
@implementation
UILocalNotification
(
APPLocalNotification
)
#pragma mark -
#pragma mark -
#pragma mark Init
methods
#pragma mark Init
/**
/**
* Initialize a local notification with the given options when calling on JS side:
* Initialize a local notification with the given options when calling on JS side:
...
@@ -59,6 +59,10 @@ static char optionsKey;
...
@@ -59,6 +59,10 @@ static char optionsKey;
self
.
repeatInterval
=
options
.
repeatInterval
;
self
.
repeatInterval
=
options
.
repeatInterval
;
self
.
alertBody
=
options
.
alertBody
;
self
.
alertBody
=
options
.
alertBody
;
self
.
soundName
=
options
.
soundName
;
self
.
soundName
=
options
.
soundName
;
if
([
self
wasInThePast
])
{
self
.
fireDate
=
[
NSDate
date
];
}
}
}
#pragma mark -
#pragma mark -
...
@@ -129,7 +133,7 @@ static char optionsKey;
...
@@ -129,7 +133,7 @@ static char optionsKey;
NSDate
*
now
=
[
NSDate
date
];
NSDate
*
now
=
[
NSDate
date
];
NSDate
*
fireDate
=
self
.
options
.
fireDate
;
NSDate
*
fireDate
=
self
.
options
.
fireDate
;
int
timespan
=
[
now
timeIntervalSinceDate
:
fireDate
];
int
timespan
=
[
now
timeIntervalSinceDate
:
fireDate
];
if
([
self
isRepeating
])
{
if
([
self
isRepeating
])
{
timespan
=
timespan
%
[
self
repeatIntervalInSeconds
];
timespan
=
timespan
%
[
self
repeatIntervalInSeconds
];
...
@@ -143,7 +147,7 @@ static char optionsKey;
...
@@ -143,7 +147,7 @@ static char optionsKey;
*/
*/
-
(
BOOL
)
wasInThePast
-
(
BOOL
)
wasInThePast
{
{
return
[
self
timeIntervalSinceFireDate
]
<
0
;
return
[
self
timeIntervalSinceFireDate
]
>
0
;
}
}
/**
/**
...
@@ -160,6 +164,22 @@ static char optionsKey;
...
@@ -160,6 +164,22 @@ static char optionsKey;
}
}
/**
/**
* If the notification was updated.
*/
-
(
BOOL
)
wasUpdated
{
NSDate
*
now
=
[
NSDate
date
];
NSDate
*
updatedAt
=
[
self
.
userInfo
objectForKey
:
@"updatedAt"
];
if
(
updatedAt
==
NULL
)
return
NO
;
int
timespan
=
[
now
timeIntervalSinceDate
:
updatedAt
];
return
timespan
<
1
;
}
/**
* If it's a repeating notification.
* If it's a repeating notification.
*/
*/
-
(
BOOL
)
isRepeating
-
(
BOOL
)
isRepeating
...
@@ -167,4 +187,27 @@ static char optionsKey;
...
@@ -167,4 +187,27 @@ static char optionsKey;
return
[
self
.
options
isRepeating
];
return
[
self
.
options
isRepeating
];
}
}
/**
* Encode the user info dict to JSON.
*/
-
(
NSString
*
)
encodeToJSON
{
NSString
*
json
;
NSData
*
data
;
NSMutableDictionary
*
obj
=
[
self
.
userInfo
mutableCopy
];
[
obj
removeObjectForKey
:
@"json"
];
[
obj
removeObjectForKey
:
@"updatedAt"
];
data
=
[
NSJSONSerialization
dataWithJSONObject
:
obj
options
:
NSJSONWritingPrettyPrinted
error
:
Nil
];
json
=
[[
NSString
alloc
]
initWithData
:
data
encoding
:
NSUTF8StringEncoding
];
return
[
json
stringByReplacingOccurrencesOfString
:
@"
\n
"
withString
:
@""
];
}
@end
@end
www/local-notification.js
View file @
1694a815
...
@@ -98,20 +98,20 @@ exports.setDefaults = function (newDefaults) {
...
@@ -98,20 +98,20 @@ exports.setDefaults = function (newDefaults) {
/**
/**
* Add a new entry to the registry
* Add a new entry to the registry
*
*
* @param {Object}
prop
s
* @param {Object}
opt
s
* The notification properties
* The notification properties
* @param {Function} callback
* @param {Function} callback
* A function to be called after the notification has been canceled
* A function to be called after the notification has been canceled
* @param {Object?} scope
* @param {Object?} scope
* The scope for the callback function
* The scope for the callback function
*/
*/
exports
.
add
=
function
(
prop
s
,
callback
,
scope
)
{
exports
.
add
=
function
(
opt
s
,
callback
,
scope
)
{
this
.
registerPermission
(
function
(
granted
)
{
this
.
registerPermission
(
function
(
granted
)
{
if
(
!
granted
)
if
(
!
granted
)
return
;
return
;
var
notifications
=
Array
.
isArray
(
props
)
?
props
:
[
prop
s
];
var
notifications
=
Array
.
isArray
(
opts
)
?
opts
:
[
opt
s
];
for
(
var
i
=
0
;
i
<
notifications
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
notifications
.
length
;
i
++
)
{
var
properties
=
notifications
[
i
];
var
properties
=
notifications
[
i
];
...
@@ -120,16 +120,12 @@ exports.add = function (props, callback, scope) {
...
@@ -120,16 +120,12 @@ exports.add = function (props, callback, scope) {
this
.
convertProperties
(
properties
);
this
.
convertProperties
(
properties
);
}
}
if
(
device
.
platform
!=
'iOS'
&&
device
.
platform
!=
'Android'
)
{
notifications
=
notifications
[
0
];
}
this
.
exec
(
'add'
,
notifications
,
callback
,
scope
);
this
.
exec
(
'add'
,
notifications
,
callback
,
scope
);
},
this
);
},
this
);
};
};
/**
/**
* Update existing notification
specified by ID
in options.
* Update existing notification
s specified by IDs
in options.
*
*
* @param {Object} options
* @param {Object} options
* The notification properties to update
* The notification properties to update
...
@@ -138,8 +134,16 @@ exports.add = function (props, callback, scope) {
...
@@ -138,8 +134,16 @@ exports.add = function (props, callback, scope) {
* @param {Object?} scope
* @param {Object?} scope
* The scope for the callback function
* The scope for the callback function
*/
*/
exports
.
update
=
function
(
options
,
callback
,
scope
)
{
exports
.
update
=
function
(
opts
,
callback
,
scope
)
{
this
.
exec
(
'update'
,
options
,
callback
,
scope
);
var
notifications
=
Array
.
isArray
(
opts
)
?
opts
:
[
opts
];
for
(
var
i
=
0
;
i
<
notifications
.
length
;
i
++
)
{
var
properties
=
notifications
[
i
];
this
.
convertProperties
(
properties
);
}
this
.
exec
(
'update'
,
notifications
,
callback
,
scope
);
};
};
/**
/**
...
@@ -154,7 +158,7 @@ exports.update = function (options, callback, scope) {
...
@@ -154,7 +158,7 @@ exports.update = function (options, callback, scope) {
*/
*/
exports
.
clear
=
function
(
ids
,
callback
,
scope
)
{
exports
.
clear
=
function
(
ids
,
callback
,
scope
)
{
ids
=
Array
.
isArray
(
ids
)
?
ids
:
[
ids
];
ids
=
Array
.
isArray
(
ids
)
?
ids
:
[
ids
];
ids
=
this
.
convertIds
(
ids
);
ids
=
this
.
convertIds
(
ids
);
this
.
exec
(
'clear'
,
ids
,
callback
,
scope
);
this
.
exec
(
'clear'
,
ids
,
callback
,
scope
);
...
@@ -188,10 +192,6 @@ exports.cancel = function (ids, callback, scope) {
...
@@ -188,10 +192,6 @@ exports.cancel = function (ids, callback, scope) {
ids
=
this
.
convertIds
(
ids
);
ids
=
this
.
convertIds
(
ids
);
if
(
device
.
platform
!=
'iOS'
&&
device
.
platform
!=
'Android'
)
{
ids
=
ids
[
0
];
}
this
.
exec
(
'cancel'
,
ids
,
callback
,
scope
);
this
.
exec
(
'cancel'
,
ids
,
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