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
afc7f250
Commit
afc7f250
authored
Jan 18, 2014
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added the ability to override notifications default properties
parent
92ae360d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
35 deletions
+104
-35
README.md
README.md
+18
-0
local-notification.js
www/local-notification.js
+86
-35
No files found.
README.md
View file @
afc7f250
...
...
@@ -49,6 +49,7 @@ More informations can be found [here](https://build.phonegap.com/plugins/356).
#### Version 0.7.0 (not yet released)
-
**Note:**
The new way of callback registration will be not compatible with previous versions! See #62
-
[
feature:
]
Added new callback registration interface and new callback types.
-
[
feature:
]
Added the ability to override notifications default properties.
#### Version 0.7.0beta1 (17.01.2014)
-
[
bugfix:
]
App throws an error on iOS if
`message`
is null.
...
...
@@ -149,6 +150,18 @@ There are 4 different callback types available. For each of them one listener ca
window
.
plugin
.
notification
.
local
.
on_callback_
=
function
(
id
,
state
,
json
)
{};
```
### getDefaults()
Gives an overview about all available notification properties for the platform and their default values. The function returns an object.
```
javascript
window
.
plugin
.
notification
.
local
.
getDefaults
();
```
### setDefaults ()
Overrides the default properties. The function takes an object as argument.
```
javascript
window
.
plugin
.
notification
.
local
.
setDefaults
(
Object
);
```
## Examples
#### Will fire every week on this day, 60 seconds from now
...
...
@@ -193,6 +206,11 @@ window.plugin.notification.local.onclick = function (id, state, json) {
}
```
### Change the default value for autoCancel
```
javascript
window
.
plugin
.
notification
.
local
.
setDefaults
({
autoCancel
:
true
});
```
## Platform specifics
### Small and large icons on Android
...
...
www/local-notification.js
View file @
afc7f250
...
...
@@ -20,59 +20,106 @@
*/
var
LocalNotification
=
function
()
{
this
.
_deafults
=
{
message
:
''
,
title
:
''
,
autoCancel
:
false
,
ongoing
:
false
,
badge
:
0
,
id
:
'0'
,
json
:
''
,
repeat
:
''
};
};
LocalNotification
.
prototype
=
{
/**
* Fügt einen neuen Eintrag zur Registry hinzu.
* Gibt alle Standardeinstellungen an.
*
* @return {Object}
*/
getDefaults
:
function
()
{
return
this
.
_deafults
;
},
/**
* Überschreibt die Standardeinstellungen.
*
* @param {Object} defaults
*/
setDefaults
:
function
(
newDefaults
)
{
var
defaults
=
this
.
getDefaults
();
for
(
var
key
in
defaults
)
{
if
(
newDefaults
[
key
]
!==
undefined
)
{
defaults
[
key
]
=
newDefaults
[
key
];
}
}
},
/**
* @private
* Merged die Eigenschaften mit den Standardwerten.
*
* @param {Object} options
* @ret
urn {Number} Die ID der Notification
* @ret
run {Object}
*/
add
:
function
(
options
)
{
var
defaults
=
{
date
:
new
Date
(),
message
:
''
,
title
:
''
,
autoCancel
:
false
,
ongoing
:
false
,
badge
:
0
,
id
:
'0'
,
json
:
''
,
repeat
:
''
};
mergeWithDefaults
:
function
(
options
)
{
var
defaults
=
this
.
getDefaults
();
for
(
var
key
in
defaults
)
{
if
(
options
[
key
]
===
undefined
)
{
options
[
key
]
=
defaults
[
key
];
}
}
return
options
;
},
/**
* @private
*/
applyPlatformSpecificOptions
:
function
()
{
var
defaults
=
this
.
_deafults
;
switch
(
device
.
platform
)
{
case
'Android'
:
defaults
.
icon
=
'icon'
;
defaults
.
smallIcon
=
null
;
defaults
.
sound
=
'TYPE_NOTIFICATION'
;
break
;
case
'iOS'
:
defaults
.
sound
=
''
;
break
;
case
'WinCE'
:
case
'Win32NT'
:
defaults
.
smallImage
=
null
;
defaults
.
image
=
null
;
defaults
.
wideImage
=
null
;
case
'Android'
:
defaults
.
icon
=
'icon'
;
defaults
.
smallIcon
=
null
;
defaults
.
sound
=
'TYPE_NOTIFICATION'
;
break
;
case
'iOS'
:
defaults
.
sound
=
''
;
break
;
case
'WinCE'
:
case
'Win32NT'
:
defaults
.
smallImage
=
null
;
defaults
.
image
=
null
;
defaults
.
wideImage
=
null
;
};
},
for
(
var
key
in
defaults
)
{
if
(
options
[
key
]
!==
undefined
)
{
defaults
[
key
]
=
options
[
key
];
}
/**
* Fügt einen neuen Eintrag zur Registry hinzu.
*
* @param {Object} options
* @return {Number} Die ID der Notification
*/
add
:
function
(
options
)
{
var
options
=
this
.
mergeWithDefaults
(
options
);
if
(
options
.
id
)
{
options
.
id
=
options
.
id
.
toString
();
}
if
(
defaults
.
i
d
)
{
defaults
.
id
=
defaults
.
id
.
toString
();
if
(
options
.
date
===
undefine
d
)
{
options
.
date
=
new
Date
();
}
if
(
typeof
default
s
.
date
==
'object'
)
{
defaults
.
date
=
Math
.
round
(
default
s
.
date
.
getTime
()
/
1000
);
if
(
typeof
option
s
.
date
==
'object'
)
{
options
.
date
=
Math
.
round
(
option
s
.
date
.
getTime
()
/
1000
);
}
cordova
.
exec
(
null
,
null
,
'LocalNotification'
,
'add'
,
[
default
s
]);
cordova
.
exec
(
null
,
null
,
'LocalNotification'
,
'add'
,
[
option
s
]);
return
default
s
.
id
;
return
option
s
.
id
;
},
/**
...
...
@@ -130,4 +177,8 @@ LocalNotification.prototype = {
var
plugin
=
new
LocalNotification
();
document
.
addEventListener
(
'deviceready'
,
function
()
{
plugin
.
applyPlatformSpecificOptions
();
},
false
);
module
.
exports
=
plugin
;
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