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
d6df078f
Commit
d6df078f
authored
Jun 30, 2017
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Custom repeat intervals based on matching date components
parent
3b148a29
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
30 deletions
+98
-30
APPNotificationOptions.h
src/ios/APPNotificationOptions.h
+0
-1
APPNotificationOptions.m
src/ios/APPNotificationOptions.m
+98
-29
No files found.
src/ios/APPNotificationOptions.h
View file @
d6df078f
...
@@ -35,7 +35,6 @@
...
@@ -35,7 +35,6 @@
@property
(
readonly
,
getter
=
userInfo
)
NSDictionary
*
userInfo
;
@property
(
readonly
,
getter
=
userInfo
)
NSDictionary
*
userInfo
;
-
(
id
)
initWithDict
:(
NSDictionary
*
)
dict
;
-
(
id
)
initWithDict
:(
NSDictionary
*
)
dict
;
-
(
BOOL
)
isRepeating
;
-
(
UNNotificationTrigger
*
)
trigger
;
-
(
UNNotificationTrigger
*
)
trigger
;
@end
@end
src/ios/APPNotificationOptions.m
View file @
d6df078f
...
@@ -165,21 +165,6 @@
...
@@ -165,21 +165,6 @@
#pragma mark Public
#pragma mark Public
/**
/**
* If the notification shall be repeating.
*
* @return [ BOOL ]
*/
-
(
BOOL
)
isRepeating
{
id
every
=
[
dict
objectForKey
:
@"every"
];
if
([
every
isKindOfClass
:
NSString
.
class
])
return
((
NSString
*
)
every
).
length
>
0
;
return
every
>
0
;
}
/**
* Specify how and when to trigger the notification.
* Specify how and when to trigger the notification.
*
*
* @return [ UNNotificationTrigger* ]
* @return [ UNNotificationTrigger* ]
...
@@ -214,6 +199,24 @@
...
@@ -214,6 +199,24 @@
#pragma mark Private
#pragma mark Private
/**
/**
* If the notification shall be repeating.
*
* @return [ BOOL ]
*/
-
(
BOOL
)
isRepeating
{
id
every
=
[
dict
objectForKey
:
@"every"
];
if
([
every
isKindOfClass
:
NSString
.
class
])
return
((
NSString
*
)
every
).
length
>
0
;
if
([
every
isKindOfClass
:
NSDictionary
.
class
])
return
((
NSDictionary
*
)
every
).
count
>
0
;
return
every
>
0
;
}
/**
* Non repeating trigger.
* Non repeating trigger.
*
*
* @return [ UNTimeIntervalNotificationTrigger* ]
* @return [ UNTimeIntervalNotificationTrigger* ]
...
@@ -236,6 +239,9 @@
...
@@ -236,6 +239,9 @@
if
([
every
isKindOfClass
:
NSString
.
class
])
if
([
every
isKindOfClass
:
NSString
.
class
])
return
[
self
repeatingTriggerWithDateMatchingComponents
];
return
[
self
repeatingTriggerWithDateMatchingComponents
];
if
([
every
isKindOfClass
:
NSDictionary
.
class
])
return
[
self
repeatingTriggerWithCustomDateMatchingComponents
];
return
[
self
repeatingTriggerWithTimeInterval
];
return
[
self
repeatingTriggerWithTimeInterval
];
}
}
...
@@ -258,7 +264,7 @@
...
@@ -258,7 +264,7 @@
}
}
/**
/**
* A repeating trigger based on a calendar time
defined by the user
.
* A repeating trigger based on a calendar time
intervals defined by the plugin
.
*
*
* @return [ UNCalendarNotificationTrigger* ]
* @return [ UNCalendarNotificationTrigger* ]
*/
*/
...
@@ -269,8 +275,27 @@
...
@@ -269,8 +275,27 @@
NSDateComponents
*
date
=
[
cal
components
:[
self
repeatInterval
]
NSDateComponents
*
date
=
[
cal
components
:[
self
repeatInterval
]
fromDate
:[
self
fireDate
]];
fromDate
:[
self
fireDate
]];
date
.
timeZone
=
[
NSTimeZone
defaultTimeZone
];
return
[
UNCalendarNotificationTrigger
triggerWithDateMatchingComponents
:
date
repeats
:
YES
];
}
/**
* A repeating trigger based on a calendar time intervals defined by the user.
*
* @return [ UNCalendarNotificationTrigger* ]
*/
-
(
UNCalendarNotificationTrigger
*
)
repeatingTriggerWithCustomDateMatchingComponents
{
NSCalendar
*
cal
=
[[
NSCalendar
alloc
]
initWithCalendarIdentifier
:
NSCalendarIdentifierGregorian
];
NSDateComponents
*
date
=
[
self
customDateComponents
];
[
date
setTimeZone
:[
NSTimeZone
defaultTimeZone
]];
date
.
calendar
=
cal
;
date
.
timeZone
=
[
NSTimeZone
defaultTimeZone
];
return
[
UNCalendarNotificationTrigger
return
[
UNCalendarNotificationTrigger
triggerWithDateMatchingComponents
:
date
repeats
:
YES
];
triggerWithDateMatchingComponents
:
date
repeats
:
YES
];
...
@@ -296,35 +321,79 @@
...
@@ -296,35 +321,79 @@
NSString
*
interval
=
[
dict
objectForKey
:
@"every"
];
NSString
*
interval
=
[
dict
objectForKey
:
@"every"
];
NSCalendarUnit
units
=
NSCalendarUnitYear
|
NSCalendarUnitMonth
|
NSCalendarUnitDay
|
NSCalendarUnitHour
|
NSCalendarUnitMinute
|
NSCalendarUnitSecond
;
NSCalendarUnit
units
=
NSCalendarUnitYear
|
NSCalendarUnitMonth
|
NSCalendarUnitDay
|
NSCalendarUnitHour
|
NSCalendarUnitMinute
|
NSCalendarUnitSecond
;
if
(
!
interval
.
length
)
return
units
;
if
([
interval
isEqualToString
:
@"second"
])
return
NSCalendarUnitNanosecond
;
if
([
interval
isEqualToString
:
@"minute"
])
if
([
interval
isEqualToString
:
@"minute"
])
return
NSCalendarUnitSecond
;
return
NSCalendarUnitSecond
;
if
([
interval
isEqualToString
:
@"hour"
])
if
([
interval
isEqualToString
:
@"hour"
])
return
NSCalendarUnitMinute
;
return
NSCalendarUnitMinute
|
NSCalendarUnitSecond
;
if
([
interval
isEqualToString
:
@"day"
])
if
([
interval
isEqualToString
:
@"day"
])
return
NSCalendarUnitHour
|
NSCalendarUnitMinute
;
return
NSCalendarUnitHour
|
NSCalendarUnitMinute
|
NSCalendarUnitSecond
;
if
([
interval
isEqualToString
:
@"week"
])
if
([
interval
isEqualToString
:
@"week"
])
return
NSCalendarUnit
Hour
|
NSCalendarUnitMinute
|
NSCalendarUnitWeekday
;
return
NSCalendarUnit
Weekday
|
NSCalendarUnitHour
|
NSCalendarUnitMinute
|
NSCalendarUnitSecond
;
if
([
interval
isEqualToString
:
@"month"
])
if
([
interval
isEqualToString
:
@"month"
])
return
NSCalendarUnit
Hour
|
NSCalendarUnitMinute
|
NSCalendarUnitDay
;
return
NSCalendarUnit
Day
|
NSCalendarUnitHour
|
NSCalendarUnitMinute
|
NSCalendarUnitSecond
;
if
([
interval
isEqualToString
:
@"year"
])
if
([
interval
isEqualToString
:
@"year"
])
return
NSCalendarUnit
Hour
|
NSCalendarUnitMinute
|
NSCalendarUnitDay
|
NSCalendarUnitMonth
;
return
NSCalendarUnit
Month
|
NSCalendarUnitDay
|
NSCalendarUnitHour
|
NSCalendarUnitMinute
|
NSCalendarUnitSecond
;
return
units
;
return
units
;
}
}
/**
/**
* The repeat interval for the notification.
*
* @return [ NSDateComponents* ]
*/
-
(
NSDateComponents
*
)
customDateComponents
{
NSDateComponents
*
date
=
[[
NSDateComponents
alloc
]
init
];
NSDictionary
*
every
=
[
dict
objectForKey
:
@"every"
];
for
(
NSString
*
key
in
every
)
{
long
value
=
[[
every
valueForKey
:
key
]
longValue
];
if
([
key
isEqualToString
:
@"second"
])
{
date
.
second
=
value
;
}
else
if
([
key
isEqualToString
:
@"minute"
])
{
date
.
minute
=
value
;
}
else
if
([
key
isEqualToString
:
@"hour"
])
{
date
.
hour
=
value
;
}
else
if
([
key
isEqualToString
:
@"day"
])
{
date
.
day
=
value
;
}
else
if
([
key
isEqualToString
:
@"weekday"
])
{
date
.
weekday
=
value
;
}
else
if
([
key
isEqualToString
:
@"weekdayOrdinal"
])
{
date
.
weekdayOrdinal
=
value
;
}
else
if
([
key
isEqualToString
:
@"week"
])
{
date
.
weekOfYear
=
value
;
}
else
if
([
key
isEqualToString
:
@"weekOfMonth"
])
{
date
.
weekOfMonth
=
value
;
}
else
if
([
key
isEqualToString
:
@"month"
])
{
date
.
month
=
value
;
}
else
if
([
key
isEqualToString
:
@"quarter"
])
{
date
.
quarter
=
value
;
}
else
if
([
key
isEqualToString
:
@"year"
])
{
date
.
year
=
value
;
}
}
return
date
;
}
/**
* Convert an assets path to an valid sound name attribute.
* Convert an assets path to an valid sound name attribute.
*
*
* @param [ NSString* ] path A relative assets file path.
* @param [ NSString* ] path A relative assets file path.
...
...
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