Commit 492924ed by Sebastián Katzer

Support for location based trigger

parent ba07d4ce
...@@ -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" />
......
/* /*
* 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 ()
...@@ -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* ]
...@@ -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];
...@@ -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 repeatingTriggerWithDateMatchingComponents]; return [self triggerWithDateMatchingComponents];
if ([every isKindOfClass:NSDictionary.class]) if ([every isKindOfClass:NSDictionary.class])
return [self repeatingTriggerWithCustomDateMatchingComponents]; return [self triggerWithCustomDateMatchingComponents];
return [self repeatingTriggerWithTimeInterval]; return [self triggerWithTimeInterval];
} }
/** /**
...@@ -361,7 +376,7 @@ ...@@ -361,7 +376,7 @@
* *
* @return [ UNTimeIntervalNotificationTrigger* ] * @return [ UNTimeIntervalNotificationTrigger* ]
*/ */
- (UNTimeIntervalNotificationTrigger*) repeatingTriggerWithTimeInterval - (UNTimeIntervalNotificationTrigger*) triggerWithTimeInterval
{ {
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*) repeatingTriggerWithDateMatchingComponents - (UNCalendarNotificationTrigger*) triggerWithDateMatchingComponents
{ {
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*) repeatingTriggerWithCustomDateMatchingComponents - (UNCalendarNotificationTrigger*) triggerWithCustomDateMatchingComponents
{ {
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 ]
......
...@@ -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 () {
// Store launchedBy notification // Set 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 () {
......
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