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
10c6988c
Commit
10c6988c
authored
Dec 18, 2013
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
`cancel` on iOS did not work (#37)
parent
adf62bf2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
21 deletions
+71
-21
README.md
README.md
+1
-0
APPLocalNotification.h
src/ios/APPLocalNotification.h
+5
-2
APPLocalNotification.m
src/ios/APPLocalNotification.m
+65
-19
No files found.
README.md
View file @
10c6988c
...
@@ -51,6 +51,7 @@ More informations can be found [here](https://build.phonegap.com/plugins/331).
...
@@ -51,6 +51,7 @@ More informations can be found [here](https://build.phonegap.com/plugins/331).
-
[
bugfix:
]
Removed extra line break on iOS if
`title`
is null or empty.
-
[
bugfix:
]
Removed extra line break on iOS if
`title`
is null or empty.
-
[
bugfix:
]
Notification on iOS will be canceled if a new one with the same ID was added.
-
[
bugfix:
]
Notification on iOS will be canceled if a new one with the same ID was added.
-
[
enhancement:
]
Added
`autoCancel`
flag.
-
[
enhancement:
]
Added
`autoCancel`
flag.
-
[
bugfix:
]
`cancel`
on iOS did not work.
#### Version 0.6.3 (12.12.2013)
#### Version 0.6.3 (12.12.2013)
-
[
bugfix:
]
Black screen on Android.
-
[
bugfix:
]
Black screen on Android.
...
...
src/ios/APPLocalNotification.h
View file @
10c6988c
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
KIND, either express or implied. See the License for the
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
specific language governing permissions and limitations
under the License.
under the License.
*/
*/
#import <Foundation/Foundation.h>
#import <Foundation/Foundation.h>
#import <Cordova/CDVPlugin.h>
#import <Cordova/CDVPlugin.h>
...
@@ -26,9 +26,12 @@
...
@@ -26,9 +26,12 @@
}
}
// Schlüssel-Präfix für alle archivierten Meldungen
extern
NSString
*
const
kAPP_LOCALNOTIFICATION
;
// Fügt einen neuen Eintrag hinzu
// Fügt einen neuen Eintrag hinzu
-
(
void
)
add
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
add
:(
CDVInvokedUrlCommand
*
)
command
;
// Entfernt d
en anhand der ID angegebenen Eintra
g
// Entfernt d
ie zur ID passende Meldun
g
-
(
void
)
cancel
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
cancel
:(
CDVInvokedUrlCommand
*
)
command
;
// Entfernt alle registrierten Einträge
// Entfernt alle registrierten Einträge
-
(
void
)
cancelAll
:(
CDVInvokedUrlCommand
*
)
command
;
-
(
void
)
cancelAll
:(
CDVInvokedUrlCommand
*
)
command
;
...
...
src/ios/APPLocalNotification.m
View file @
10c6988c
...
@@ -23,6 +23,9 @@
...
@@ -23,6 +23,9 @@
@interface
APPLocalNotification
(
Private
)
@interface
APPLocalNotification
(
Private
)
// Archiviert die Meldungen, sodass sie später abgerufen werden kann
-
(
void
)
archiveNotification
:(
UILocalNotification
*
)
notification
;
// Nachschlagewerk für Zeitintervallangaben
-
(
NSMutableDictionary
*
)
repeatDict
;
-
(
NSMutableDictionary
*
)
repeatDict
;
// Alle zusätzlichen Metadaten der Notification als Hash
// Alle zusätzlichen Metadaten der Notification als Hash
-
(
NSDictionary
*
)
userDict
:(
NSMutableDictionary
*
)
options
;
-
(
NSDictionary
*
)
userDict
:(
NSMutableDictionary
*
)
options
;
...
@@ -30,9 +33,14 @@
...
@@ -30,9 +33,14 @@
-
(
UILocalNotification
*
)
notificationWithProperties
:(
NSMutableDictionary
*
)
options
;
-
(
UILocalNotification
*
)
notificationWithProperties
:(
NSMutableDictionary
*
)
options
;
// Ruft die JS-Callbacks auf, nachdem eine Notification eingegangen ist
// Ruft die JS-Callbacks auf, nachdem eine Notification eingegangen ist
-
(
void
)
didReceiveLocalNotification
:(
NSNotification
*
)
localNotification
;
-
(
void
)
didReceiveLocalNotification
:(
NSNotification
*
)
localNotification
;
// Hilfsmethode gibt an, ob er String NULL oder Empty ist
-
(
BOOL
)
strIsNullOrEmpty
:(
NSString
*
)
str
;
@end
@end
// Schlüssel-Präfix für alle archivierten Meldungen
NSString
*
const
kAPP_LOCALNOTIFICATION
=
@"APP_LOCALNOTIFICATION"
;
@implementation
APPLocalNotification
@implementation
APPLocalNotification
...
@@ -50,13 +58,14 @@
...
@@ -50,13 +58,14 @@
NSString
*
notificationId
=
[
notification
.
userInfo
objectForKey
:
@"id"
];
NSString
*
notificationId
=
[
notification
.
userInfo
objectForKey
:
@"id"
];
[
self
cancelNotificationWithId
:
notificationId
];
[
self
cancelNotificationWithId
:
notificationId
];
[
self
archiveNotification
:
notification
];
[[
UIApplication
sharedApplication
]
scheduleLocalNotification
:
notification
];
[[
UIApplication
sharedApplication
]
scheduleLocalNotification
:
notification
];
}];
}];
}
}
/**
/**
* Entfernt d
en anhand der ID angegebenen Eintra
g.
* Entfernt d
ie zur ID passende Meldun
g.
*
*
* @param {NSString} id Die ID der Notification
* @param {NSString} id Die ID der Notification
*/
*/
...
@@ -75,36 +84,65 @@
...
@@ -75,36 +84,65 @@
*/
*/
-
(
void
)
cancelAll
:(
CDVInvokedUrlCommand
*
)
command
-
(
void
)
cancelAll
:(
CDVInvokedUrlCommand
*
)
command
{
{
[
self
.
commandDelegate
runInBackground
:
^
{
NSDictionary
*
entries
=
[[
NSUserDefaults
standardUserDefaults
]
dictionaryRepresentation
];
for
(
NSString
*
key
in
[
entries
allKeys
])
{
if
([
key
hasPrefix
:
kAPP_LOCALNOTIFICATION
])
{
[[
NSUserDefaults
standardUserDefaults
]
removeObjectForKey
:
key
];
}
}
[[
NSUserDefaults
standardUserDefaults
]
synchronize
];
[[
UIApplication
sharedApplication
]
cancelAllLocalNotifications
];
[[
UIApplication
sharedApplication
]
cancelAllLocalNotifications
];
}];
}
}
/**
/**
* Entfernt den
anhand der ID angegeben
en Eintrag.
* Entfernt den
zur ID passend
en Eintrag.
*
*
* @param {NSString} id Die ID der Notification
* @param {NSString} id Die ID der Notification
*/
*/
-
(
void
)
cancelNotificationWithId
:(
NSString
*
)
notificationI
d
-
(
void
)
cancelNotificationWithId
:(
NSString
*
)
i
d
{
{
NSArray
*
notifications
=
[[
UIApplication
sharedApplication
]
scheduledLocalNotifications
];
if
(
!
[
self
strIsNullOrEmpty
:
id
])
{
NSString
*
key
=
[
kAPP_LOCALNOTIFICATION
stringByAppendingString
:
id
];
NSData
*
data
=
[[
NSUserDefaults
standardUserDefaults
]
objectForKey
:
key
];
if
(
notificationId
==
(
NSString
*
)[
NSNull
null
]
||
[
notificationId
isEqualToString
:
@""
]
)
if
(
data
)
{
{
return
;
UILocalNotification
*
notification
=
[
NSKeyedUnarchiver
unarchiveObjectWithData
:
data
];
[[
NSUserDefaults
standardUserDefaults
]
removeObjectForKey
:
key
];
[[
UIApplication
sharedApplication
]
cancelLocalNotification
:
notification
];
}
}
}
}
for
(
UILocalNotification
*
notification
in
notifications
)
/**
{
* Archiviert die Meldungen, sodass sie später abgerufen werden kann.
*
* @param {UILocalNotification} notification
*/
-
(
void
)
archiveNotification
:(
UILocalNotification
*
)
notification
{
NSString
*
id
=
[
notification
.
userInfo
objectForKey
:
@"id"
];
NSString
*
id
=
[
notification
.
userInfo
objectForKey
:
@"id"
];
if
([
notificationId
isEqualToString
:
id
])
if
(
!
[
self
strIsNullOrEmpty
:
id
])
{
{
[[
UIApplication
sharedApplication
]
cancelLocalNotification
:
notification
];
NSData
*
data
=
[
NSKeyedArchiver
archivedDataWithRootObject
:
notification
];
}
NSString
*
key
=
[
kAPP_LOCALNOTIFICATION
stringByAppendingString
:
id
];
[[
NSUserDefaults
standardUserDefaults
]
setObject
:
data
forKey
:
key
];
}
}
}
}
/**
/**
*
@private
*
Nachschlagewerk für Zeitintervallangaben.
*/
*/
-
(
NSMutableDictionary
*
)
repeatDict
-
(
NSMutableDictionary
*
)
repeatDict
{
{
...
@@ -139,7 +177,7 @@
...
@@ -139,7 +177,7 @@
{
{
UILocalNotification
*
notification
=
[[
UILocalNotification
alloc
]
init
];
UILocalNotification
*
notification
=
[[
UILocalNotification
alloc
]
init
];
double
timestamp
=
[[
options
objectForKey
:
@"date"
]
doubleValue
]
+
1
;
double
timestamp
=
[[
options
objectForKey
:
@"date"
]
doubleValue
];
NSString
*
msg
=
[
options
objectForKey
:
@"message"
];
NSString
*
msg
=
[
options
objectForKey
:
@"message"
];
NSString
*
title
=
[
options
objectForKey
:
@"title"
];
NSString
*
title
=
[
options
objectForKey
:
@"title"
];
NSString
*
sound
=
[
options
objectForKey
:
@"sound"
];
NSString
*
sound
=
[
options
objectForKey
:
@"sound"
];
...
@@ -154,9 +192,9 @@
...
@@ -154,9 +192,9 @@
notification
.
applicationIconBadgeNumber
=
badge
;
notification
.
applicationIconBadgeNumber
=
badge
;
if
(
!
(
msg
==
(
NSString
*
)[
NSNull
null
]
||
[
msg
isEqualToString
:
@""
])
)
if
(
!
[
self
strIsNullOrEmpty
:
msg
]
)
{
{
if
(
!
(
title
==
(
NSString
*
)[
NSNull
null
]
||
[
title
isEqualToString
:
@""
])
)
if
(
!
[
self
strIsNullOrEmpty
:
title
]
)
{
{
notification
.
alertBody
=
[
NSString
stringWithFormat
:
@"%@
\n
%@"
,
title
,
msg
];
notification
.
alertBody
=
[
NSString
stringWithFormat
:
@"%@
\n
%@"
,
title
,
msg
];
}
}
...
@@ -196,14 +234,14 @@
...
@@ -196,14 +234,14 @@
if
(
autoCancel
&&
!
isActive
)
if
(
autoCancel
&&
!
isActive
)
{
{
[
[
UIApplication
sharedApplication
]
cancelLocalNotification
:
notification
];
[
self
cancelNotificationWithId
:
id
];
}
}
if
(
callbackFn
&&
callbackFn
.
length
>
0
)
if
(
!
[
self
strIsNullOrEmpty
:
callbackFn
]
)
{
{
NSString
*
callback
=
[
NSString
stringWithFormat
:
@"setTimeout('%@(%@)',0)"
,
callbackFn
,
id
];
NSString
*
js
=
[
NSString
stringWithFormat
:
@"setTimeout('%@(%@)',0)"
,
callbackFn
,
id
];
[
self
writeJavascript
:
callback
];
[
self
writeJavascript
:
js
];
}
}
}
}
...
@@ -215,4 +253,12 @@
...
@@ -215,4 +253,12 @@
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
didReceiveLocalNotification
:
)
name
:
CDVLocalNotification
object
:
nil
];
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
didReceiveLocalNotification
:
)
name
:
CDVLocalNotification
object
:
nil
];
}
}
/**
* Hilfsmethode gibt an, ob er String NULL oder Empty ist.
*/
-
(
BOOL
)
strIsNullOrEmpty
:
(
NSString
*
)
str
{
return
(
str
==
(
NSString
*
)[
NSNull
null
]
||
[
str
isEqualToString
:
@""
])
?
YES
:
NO
;
}
@end
@end
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