Commit 1552ffc9 by Sebastián Katzer

Implemented new trigger property for iOS

parent 44a0da5c
...@@ -61,18 +61,6 @@ ...@@ -61,18 +61,6 @@
#pragma mark Properties #pragma mark Properties
/** /**
* The type for the notification.
*
* @return [ NSString* ]
*/
- (NSString*) triggerType
{
NSString* type = [dict objectForKey:@"trigger"];
return type.length ? type : @"normal";
}
/**
* The ID for the notification. * The ID for the notification.
* *
* @return [ NSNumber* ] * @return [ NSNumber* ]
...@@ -280,12 +268,12 @@ ...@@ -280,12 +268,12 @@
*/ */
- (UNNotificationTrigger*) trigger - (UNNotificationTrigger*) trigger
{ {
NSString* type = [self triggerType]; NSString* type = [self valueForTriggerOption:@"type"];
if ([type isEqualToString:@"location"]) if ([type isEqualToString:@"location"])
return [self triggerWithRegion]; return [self triggerWithRegion];
if (![type isEqualToString:@"date"]) if (![type isEqualToString:@"calendar"])
NSLog(@"Unknown type: %@", type); NSLog(@"Unknown type: %@", type);
if ([self isRepeating]) if ([self isRepeating])
...@@ -315,6 +303,11 @@ ...@@ -315,6 +303,11 @@
#pragma mark - #pragma mark -
#pragma mark Private #pragma mark Private
- (id) valueForTriggerOption:(NSString*)key
{
return [[dict objectForKey:@"trigger"] objectForKey:key];
}
/** /**
* The date when to fire the notification. * The date when to fire the notification.
* *
...@@ -322,8 +315,7 @@ ...@@ -322,8 +315,7 @@
*/ */
- (NSDate*) triggerDate - (NSDate*) triggerDate
{ {
double timestamp = [[dict objectForKey:@"at"] double timestamp = [[self valueForTriggerOption:@"at"] doubleValue];
doubleValue];
return [NSDate dateWithTimeIntervalSince1970:timestamp]; return [NSDate dateWithTimeIntervalSince1970:timestamp];
} }
...@@ -335,7 +327,7 @@ ...@@ -335,7 +327,7 @@
*/ */
- (BOOL) isRepeating - (BOOL) isRepeating
{ {
id every = [dict objectForKey:@"every"]; id every = [self valueForTriggerOption:@"every"];
if ([every isKindOfClass:NSString.class]) if ([every isKindOfClass:NSString.class])
return ((NSString*) every).length > 0; return ((NSString*) every).length > 0;
...@@ -364,7 +356,7 @@ ...@@ -364,7 +356,7 @@
*/ */
- (UNNotificationTrigger*) repeatingTrigger - (UNNotificationTrigger*) repeatingTrigger
{ {
id every = [dict objectForKey:@"every"]; id every = [self valueForTriggerOption:@"every"];
if ([every isKindOfClass:NSString.class]) if ([every isKindOfClass:NSString.class])
return [self triggerWithDateMatchingComponents]; return [self triggerWithDateMatchingComponents];
...@@ -382,7 +374,7 @@ ...@@ -382,7 +374,7 @@
*/ */
- (UNTimeIntervalNotificationTrigger*) triggerWithTimeInterval - (UNTimeIntervalNotificationTrigger*) triggerWithTimeInterval
{ {
long interval = [[dict objectForKey:@"every"] longValue]; long interval = [[self valueForTriggerOption:@"every"] longValue];
if (interval < 60) { if (interval < 60) {
NSLog(@"time interval must be at least 60 if repeating"); NSLog(@"time interval must be at least 60 if repeating");
...@@ -438,8 +430,8 @@ ...@@ -438,8 +430,8 @@
*/ */
- (UNLocationNotificationTrigger*) triggerWithRegion - (UNLocationNotificationTrigger*) triggerWithRegion
{ {
NSArray* center = [dict objectForKey:@"center"]; NSArray* center = [self valueForTriggerOption:@"center"];
double radius = [[dict objectForKey:@"radius"] doubleValue]; double radius = [[self valueForTriggerOption:@"radius"] doubleValue];
CLLocationCoordinate2D coord = CLLocationCoordinate2D coord =
CLLocationCoordinate2DMake([center[0] doubleValue], [center[1] doubleValue]); CLLocationCoordinate2DMake([center[0] doubleValue], [center[1] doubleValue]);
...@@ -449,8 +441,8 @@ ...@@ -449,8 +441,8 @@
radius:radius radius:radius
identifier:self.identifier]; identifier:self.identifier];
region.notifyOnEntry = [[dict objectForKey:@"notifyOnEntry"] boolValue]; region.notifyOnEntry = [[self valueForTriggerOption:@"notifyOnEntry"] boolValue];
region.notifyOnExit = [[dict objectForKey:@"notifyOnExit"] boolValue]; region.notifyOnExit = [[self valueForTriggerOption:@"notifyOnExit"] boolValue];
return [UNLocationNotificationTrigger triggerWithRegion:region repeats:YES]; return [UNLocationNotificationTrigger triggerWithRegion:region repeats:YES];
} }
...@@ -472,7 +464,7 @@ ...@@ -472,7 +464,7 @@
*/ */
- (NSCalendarUnit) repeatInterval - (NSCalendarUnit) repeatInterval
{ {
NSString* interval = [dict objectForKey:@"every"]; NSString* interval = [self valueForTriggerOption:@"every"];
NSCalendarUnit units = NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond; NSCalendarUnit units = NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond;
if ([interval isEqualToString:@"minute"]) if ([interval isEqualToString:@"minute"])
...@@ -504,7 +496,7 @@ ...@@ -504,7 +496,7 @@
- (NSDateComponents*) customDateComponents - (NSDateComponents*) customDateComponents
{ {
NSDateComponents* date = [[NSDateComponents alloc] init]; NSDateComponents* date = [[NSDateComponents alloc] init];
NSDictionary* every = [dict objectForKey:@"every"]; NSDictionary* every = [self valueForTriggerOption:@"every"];
for (NSString* key in every) { for (NSString* key in every) {
long value = [[every valueForKey:key] longValue]; long value = [[every valueForKey:key] longValue];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment