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
492924ed
Commit
492924ed
authored
Jul 04, 2017
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for location based trigger
parent
ba07d4ce
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
33 deletions
+76
-33
plugin.xml
plugin.xml
+1
-0
APPNotificationOptions.m
src/ios/APPNotificationOptions.m
+71
-32
local-notification-util.js
www/local-notification-util.js
+4
-1
No files found.
plugin.xml
View file @
492924ed
...
@@ -54,6 +54,7 @@
...
@@ -54,6 +54,7 @@
</config-file>
</config-file>
<framework
src=
"UserNotifications.framework"
/>
<framework
src=
"UserNotifications.framework"
/>
<framework
src=
"CoreLocation.framework"
/>
<header-file
src=
"src/ios/APPLocalNotification.h"
/>
<header-file
src=
"src/ios/APPLocalNotification.h"
/>
<source-file
src=
"src/ios/APPLocalNotification.m"
/>
<source-file
src=
"src/ios/APPLocalNotification.m"
/>
...
...
src/ios/APPNotificationOptions.m
View file @
492924ed
/*
/*
* Copyright (c) 2013-2015 by appPlant UG. All rights reserved.
*
* @APPPLANT_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apache License
* as defined in and that are subject to the Apache License
* Version 2.0 (the 'License'). You may not use this file except in
* Version 2.0 (the 'License'). You may not use this file except in
...
@@ -17,13 +13,12 @@
...
@@ -17,13 +13,12 @@
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* Please see the License for the specific language governing rights and
* limitations under the License.
* limitations under the License.
*
* @APPPLANT_LICENSE_HEADER_END@
*/
*/
#import "APPNotificationOptions.h"
#import "APPNotificationOptions.h"
#import "UNUserNotificationCenter+APPLocalNotification.h"
#import "UNUserNotificationCenter+APPLocalNotification.h"
@import
CoreLocation
;
@import
UserNotifications
;
@import
UserNotifications
;
@interface
APPNotificationOptions
()
@interface
APPNotificationOptions
()
...
@@ -52,7 +47,7 @@
...
@@ -52,7 +47,7 @@
self
=
[
self
init
];
self
=
[
self
init
];
self
.
dict
=
dictionary
;
self
.
dict
=
dictionary
;
[
self
actions
];
[
self
actions
];
return
self
;
return
self
;
...
@@ -62,6 +57,18 @@
...
@@ -62,6 +57,18 @@
#pragma mark Properties
#pragma mark Properties
/**
/**
* The type for the notification.
*
* @return [ NSString* ]
*/
-
(
NSString
*
)
type
{
NSString
*
type
=
[
dict
objectForKey
:
@"type"
];
return
type
.
length
?
type
:
@"normal"
;
}
/**
* The ID for the notification.
* The ID for the notification.
*
*
* @return [ NSNumber* ]
* @return [ NSNumber* ]
...
@@ -123,7 +130,7 @@
...
@@ -123,7 +130,7 @@
-
(
NSNumber
*
)
badge
-
(
NSNumber
*
)
badge
{
{
id
value
=
[
dict
objectForKey
:
@"badge"
];
id
value
=
[
dict
objectForKey
:
@"badge"
];
return
(
value
==
NULL
)
?
NULL
:
[
NSNumber
numberWithInt
:[
value
intValue
]];
return
(
value
==
NULL
)
?
NULL
:
[
NSNumber
numberWithInt
:[
value
intValue
]];
}
}
...
@@ -135,7 +142,7 @@
...
@@ -135,7 +142,7 @@
-
(
NSString
*
)
categoryId
-
(
NSString
*
)
categoryId
{
{
NSString
*
value
=
[
dict
objectForKey
:
@"actionGroupId"
];
NSString
*
value
=
[
dict
objectForKey
:
@"actionGroupId"
];
return
value
.
length
?
value
:
kAPPGeneralCategory
;
return
value
.
length
?
value
:
kAPPGeneralCategory
;
}
}
...
@@ -175,10 +182,10 @@
...
@@ -175,10 +182,10 @@
{
{
NSArray
*
paths
=
[
dict
objectForKey
:
@"attachments"
];
NSArray
*
paths
=
[
dict
objectForKey
:
@"attachments"
];
NSMutableArray
*
attachments
=
[[
NSMutableArray
alloc
]
init
];
NSMutableArray
*
attachments
=
[[
NSMutableArray
alloc
]
init
];
if
(
!
paths
)
if
(
!
paths
)
return
attachments
;
return
attachments
;
for
(
NSString
*
path
in
paths
)
{
for
(
NSString
*
path
in
paths
)
{
NSURL
*
url
=
[
self
urlForAttachmentPath
:
path
];
NSURL
*
url
=
[
self
urlForAttachmentPath
:
path
];
...
@@ -187,12 +194,12 @@
...
@@ -187,12 +194,12 @@
URL
:
url
URL
:
url
options
:
NULL
options
:
NULL
error
:
NULL
];
error
:
NULL
];
if
(
attachment
)
{
if
(
attachment
)
{
[
attachments
addObject
:
attachment
];
[
attachments
addObject
:
attachment
];
}
}
}
}
return
attachments
;
return
attachments
;
}
}
...
@@ -205,10 +212,10 @@
...
@@ -205,10 +212,10 @@
{
{
NSArray
*
items
=
[
dict
objectForKey
:
@"actions"
];
NSArray
*
items
=
[
dict
objectForKey
:
@"actions"
];
NSMutableArray
*
actions
=
[[
NSMutableArray
alloc
]
init
];
NSMutableArray
*
actions
=
[[
NSMutableArray
alloc
]
init
];
if
(
!
items
)
if
(
!
items
)
return
actions
;
return
actions
;
for
(
NSDictionary
*
item
in
items
)
{
for
(
NSDictionary
*
item
in
items
)
{
NSString
*
id
=
[
item
objectForKey
:
@"id"
];
NSString
*
id
=
[
item
objectForKey
:
@"id"
];
NSString
*
title
=
[
item
objectForKey
:
@"title"
];
NSString
*
title
=
[
item
objectForKey
:
@"title"
];
...
@@ -216,27 +223,27 @@
...
@@ -216,27 +223,27 @@
UNNotificationActionOptions
options
=
UNNotificationActionOptionNone
;
UNNotificationActionOptions
options
=
UNNotificationActionOptionNone
;
UNNotificationAction
*
action
;
UNNotificationAction
*
action
;
if
([[
item
objectForKey
:
@"launch"
]
boolValue
])
{
if
([[
item
objectForKey
:
@"launch"
]
boolValue
])
{
options
=
UNNotificationActionOptionForeground
;
options
=
UNNotificationActionOptionForeground
;
}
}
if
([[
item
objectForKey
:
@"ui"
]
isEqualToString
:
@"decline"
])
{
if
([[
item
objectForKey
:
@"ui"
]
isEqualToString
:
@"decline"
])
{
options
=
options
|
UNNotificationActionOptionDestructive
;
options
=
options
|
UNNotificationActionOptionDestructive
;
}
}
if
([[
item
objectForKey
:
@"needsAuth"
]
boolValue
])
{
if
([[
item
objectForKey
:
@"needsAuth"
]
boolValue
])
{
options
=
options
|
UNNotificationActionOptionAuthenticationRequired
;
options
=
options
|
UNNotificationActionOptionAuthenticationRequired
;
}
}
if
([
type
isEqualToString
:
@"input"
])
{
if
([
type
isEqualToString
:
@"input"
])
{
NSString
*
submitTitle
=
[
item
objectForKey
:
@"submitTitle"
];
NSString
*
submitTitle
=
[
item
objectForKey
:
@"submitTitle"
];
NSString
*
placeholder
=
[
item
objectForKey
:
@"emptyText"
];
NSString
*
placeholder
=
[
item
objectForKey
:
@"emptyText"
];
if
(
!
submitTitle
.
length
)
{
if
(
!
submitTitle
.
length
)
{
submitTitle
=
@"Submit"
;
submitTitle
=
@"Submit"
;
}
}
action
=
[
UNTextInputNotificationAction
actionWithIdentifier
:
id
action
=
[
UNTextInputNotificationAction
actionWithIdentifier
:
id
title
:
title
title
:
title
options
:
options
options
:
options
...
@@ -250,12 +257,12 @@
...
@@ -250,12 +257,12 @@
}
else
{
}
else
{
NSLog
(
@"Unknown action type: %@"
,
type
);
NSLog
(
@"Unknown action type: %@"
,
type
);
}
}
if
(
action
)
{
if
(
action
)
{
[
actions
addObject
:
action
];
[
actions
addObject
:
action
];
}
}
}
}
return
actions
;
return
actions
;
}
}
...
@@ -269,6 +276,14 @@
...
@@ -269,6 +276,14 @@
*/
*/
-
(
UNNotificationTrigger
*
)
trigger
-
(
UNNotificationTrigger
*
)
trigger
{
{
NSString
*
type
=
[
self
type
];
if
([
type
isEqualToString
:
@"location"
])
return
[
self
triggerWithRegion
];
if
(
!
[
type
isEqualToString
:
@"normal"
])
NSLog
(
@"Unknown type: %@"
,
type
);
if
([
self
isRepeating
])
if
([
self
isRepeating
])
return
[
self
repeatingTrigger
];
return
[
self
repeatingTrigger
];
...
@@ -305,7 +320,7 @@
...
@@ -305,7 +320,7 @@
{
{
double
timestamp
=
[[
dict
objectForKey
:
@"at"
]
double
timestamp
=
[[
dict
objectForKey
:
@"at"
]
doubleValue
];
doubleValue
];
return
[
NSDate
dateWithTimeIntervalSince1970
:
timestamp
];
return
[
NSDate
dateWithTimeIntervalSince1970
:
timestamp
];
}
}
...
@@ -348,12 +363,12 @@
...
@@ -348,12 +363,12 @@
id
every
=
[
dict
objectForKey
:
@"every"
];
id
every
=
[
dict
objectForKey
:
@"every"
];
if
([
every
isKindOfClass
:
NSString
.
class
])
if
([
every
isKindOfClass
:
NSString
.
class
])
return
[
self
repeatingT
riggerWithDateMatchingComponents
];
return
[
self
t
riggerWithDateMatchingComponents
];
if
([
every
isKindOfClass
:
NSDictionary
.
class
])
if
([
every
isKindOfClass
:
NSDictionary
.
class
])
return
[
self
repeatingT
riggerWithCustomDateMatchingComponents
];
return
[
self
t
riggerWithCustomDateMatchingComponents
];
return
[
self
repeatingT
riggerWithTimeInterval
];
return
[
self
t
riggerWithTimeInterval
];
}
}
/**
/**
...
@@ -361,7 +376,7 @@
...
@@ -361,7 +376,7 @@
*
*
* @return [ UNTimeIntervalNotificationTrigger* ]
* @return [ UNTimeIntervalNotificationTrigger* ]
*/
*/
-
(
UNTimeIntervalNotificationTrigger
*
)
repeatingT
riggerWithTimeInterval
-
(
UNTimeIntervalNotificationTrigger
*
)
t
riggerWithTimeInterval
{
{
long
interval
=
[[
dict
objectForKey
:
@"every"
]
longValue
];
long
interval
=
[[
dict
objectForKey
:
@"every"
]
longValue
];
...
@@ -379,7 +394,7 @@
...
@@ -379,7 +394,7 @@
*
*
* @return [ UNCalendarNotificationTrigger* ]
* @return [ UNCalendarNotificationTrigger* ]
*/
*/
-
(
UNCalendarNotificationTrigger
*
)
repeatingT
riggerWithDateMatchingComponents
-
(
UNCalendarNotificationTrigger
*
)
t
riggerWithDateMatchingComponents
{
{
NSCalendar
*
cal
=
[[
NSCalendar
alloc
]
NSCalendar
*
cal
=
[[
NSCalendar
alloc
]
initWithCalendarIdentifier
:
NSCalendarIdentifierGregorian
];
initWithCalendarIdentifier
:
NSCalendarIdentifierGregorian
];
...
@@ -398,7 +413,7 @@
...
@@ -398,7 +413,7 @@
*
*
* @return [ UNCalendarNotificationTrigger* ]
* @return [ UNCalendarNotificationTrigger* ]
*/
*/
-
(
UNCalendarNotificationTrigger
*
)
repeatingT
riggerWithCustomDateMatchingComponents
-
(
UNCalendarNotificationTrigger
*
)
t
riggerWithCustomDateMatchingComponents
{
{
NSCalendar
*
cal
=
[[
NSCalendar
alloc
]
NSCalendar
*
cal
=
[[
NSCalendar
alloc
]
initWithCalendarIdentifier
:
NSCalendarIdentifierGregorian
];
initWithCalendarIdentifier
:
NSCalendarIdentifierGregorian
];
...
@@ -413,6 +428,30 @@
...
@@ -413,6 +428,30 @@
}
}
/**
/**
* A repeating trigger based on a location region.
*
* @return [ UNLocationNotificationTrigger* ]
*/
-
(
UNLocationNotificationTrigger
*
)
triggerWithRegion
{
NSArray
*
center
=
[
dict
objectForKey
:
@"center"
];
double
radius
=
[[
dict
objectForKey
:
@"radius"
]
doubleValue
];
CLLocationCoordinate2D
coord
=
CLLocationCoordinate2DMake
([
center
[
0
]
doubleValue
],
[
center
[
1
]
doubleValue
]);
CLCircularRegion
*
region
=
[[
CLCircularRegion
alloc
]
initWithCenter
:
coord
radius
:
radius
identifier
:
self
.
identifier
];
region
.
notifyOnEntry
=
[[
dict
objectForKey
:
@"notifyOnEntry"
]
boolValue
];
region
.
notifyOnExit
=
[[
dict
objectForKey
:
@"notifyOnExit"
]
boolValue
];
return
[
UNLocationNotificationTrigger
triggerWithRegion
:
region
repeats
:
YES
];
}
/**
* The time interval between the next fire date and now.
* The time interval between the next fire date and now.
*
*
* @return [ double ]
* @return [ double ]
...
@@ -602,7 +641,7 @@
...
@@ -602,7 +641,7 @@
if
([
path
isEqualToString
:
@"res://icon"
])
{
if
([
path
isEqualToString
:
@"res://icon"
])
{
path
=
@"res://AppIcon60x60@3x.png"
;
path
=
@"res://AppIcon60x60@3x.png"
;
}
}
NSString
*
absPath
;
NSString
*
absPath
;
absPath
=
[
path
stringByReplacingOccurrencesOfString
:
@"res:/"
absPath
=
[
path
stringByReplacingOccurrencesOfString
:
@"res:/"
withString
:
@""
];
withString
:
@""
];
...
@@ -628,7 +667,7 @@
...
@@ -628,7 +667,7 @@
NSFileManager
*
fm
=
[
NSFileManager
defaultManager
];
NSFileManager
*
fm
=
[
NSFileManager
defaultManager
];
NSBundle
*
mainBundle
=
[
NSBundle
mainBundle
];
NSBundle
*
mainBundle
=
[
NSBundle
mainBundle
];
NSString
*
bundlePath
=
[
mainBundle
bundlePath
];
NSString
*
bundlePath
=
[
mainBundle
bundlePath
];
NSString
*
absPath
;
NSString
*
absPath
;
absPath
=
[
path
stringByReplacingOccurrencesOfString
:
@"file:/"
absPath
=
[
path
stringByReplacingOccurrencesOfString
:
@"file:/"
withString
:
@"/www"
];
withString
:
@"/www"
];
...
...
www/local-notification-util.js
View file @
492924ed
...
@@ -21,6 +21,7 @@ var exec = require('cordova/exec'),
...
@@ -21,6 +21,7 @@ var exec = require('cordova/exec'),
// Default values
// Default values
exports
.
_defaults
=
{
exports
.
_defaults
=
{
id
:
0
,
id
:
0
,
type
:
'normal'
,
text
:
''
,
text
:
''
,
title
:
''
,
title
:
''
,
sound
:
'res://platform_default'
,
sound
:
'res://platform_default'
,
...
@@ -54,6 +55,8 @@ exports.applyPlatformSpecificOptions = function () {
...
@@ -54,6 +55,8 @@ exports.applyPlatformSpecificOptions = function () {
break
;
break
;
case
'iOS'
:
case
'iOS'
:
defaults
.
attachments
=
undefined
;
defaults
.
attachments
=
undefined
;
defaults
.
region
=
undefined
;
defaults
.
radius
=
undefined
;
break
;
break
;
}
}
};
};
...
@@ -307,7 +310,7 @@ channel.deviceready.subscribe(function () {
...
@@ -307,7 +310,7 @@ channel.deviceready.subscribe(function () {
// Called before 'deviceready' event
// Called before 'deviceready' event
channel
.
onCordovaReady
.
subscribe
(
function
()
{
channel
.
onCordovaReady
.
subscribe
(
function
()
{
// S
tore launchedBy notification
// S
et launchDetails object
exports
.
exec
(
'launchDetails'
);
exports
.
exec
(
'launchDetails'
);
// Device plugin is ready now
// Device plugin is ready now
channel
.
onCordovaInfoReady
.
subscribe
(
function
()
{
channel
.
onCordovaInfoReady
.
subscribe
(
function
()
{
...
...
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