Commit 492924ed by Sebastián Katzer

Support for location based trigger

parent ba07d4ce
......@@ -54,6 +54,7 @@
</config-file>
<framework src="UserNotifications.framework" />
<framework src="CoreLocation.framework" />
<header-file src="src/ios/APPLocalNotification.h" />
<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
* as defined in and that are subject to the Apache License
* Version 2.0 (the 'License'). You may not use this file except in
......@@ -17,13 +13,12 @@
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPPLANT_LICENSE_HEADER_END@
*/
#import "APPNotificationOptions.h"
#import "UNUserNotificationCenter+APPLocalNotification.h"
@import CoreLocation;
@import UserNotifications;
@interface APPNotificationOptions ()
......@@ -62,6 +57,18 @@
#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.
*
* @return [ NSNumber* ]
......@@ -269,6 +276,14 @@
*/
- (UNNotificationTrigger*) trigger
{
NSString* type = [self type];
if ([type isEqualToString:@"location"])
return [self triggerWithRegion];
if (![type isEqualToString:@"normal"])
NSLog(@"Unknown type: %@", type);
if ([self isRepeating])
return [self repeatingTrigger];
......@@ -348,12 +363,12 @@
id every = [dict objectForKey:@"every"];
if ([every isKindOfClass:NSString.class])
return [self repeatingTriggerWithDateMatchingComponents];
return [self triggerWithDateMatchingComponents];
if ([every isKindOfClass:NSDictionary.class])
return [self repeatingTriggerWithCustomDateMatchingComponents];
return [self triggerWithCustomDateMatchingComponents];
return [self repeatingTriggerWithTimeInterval];
return [self triggerWithTimeInterval];
}
/**
......@@ -361,7 +376,7 @@
*
* @return [ UNTimeIntervalNotificationTrigger* ]
*/
- (UNTimeIntervalNotificationTrigger*) repeatingTriggerWithTimeInterval
- (UNTimeIntervalNotificationTrigger*) triggerWithTimeInterval
{
long interval = [[dict objectForKey:@"every"] longValue];
......@@ -379,7 +394,7 @@
*
* @return [ UNCalendarNotificationTrigger* ]
*/
- (UNCalendarNotificationTrigger*) repeatingTriggerWithDateMatchingComponents
- (UNCalendarNotificationTrigger*) triggerWithDateMatchingComponents
{
NSCalendar* cal = [[NSCalendar alloc]
initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
......@@ -398,7 +413,7 @@
*
* @return [ UNCalendarNotificationTrigger* ]
*/
- (UNCalendarNotificationTrigger*) repeatingTriggerWithCustomDateMatchingComponents
- (UNCalendarNotificationTrigger*) triggerWithCustomDateMatchingComponents
{
NSCalendar* cal = [[NSCalendar alloc]
initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
......@@ -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.
*
* @return [ double ]
......
......@@ -21,6 +21,7 @@ var exec = require('cordova/exec'),
// Default values
exports._defaults = {
id: 0,
type: 'normal',
text: '',
title: '',
sound: 'res://platform_default',
......@@ -54,6 +55,8 @@ exports.applyPlatformSpecificOptions = function () {
break;
case 'iOS':
defaults.attachments = undefined;
defaults.region = undefined;
defaults.radius = undefined;
break;
}
};
......@@ -307,7 +310,7 @@ channel.deviceready.subscribe(function () {
// Called before 'deviceready' event
channel.onCordovaReady.subscribe(function () {
// Store launchedBy notification
// Set launchDetails object
exports.exec('launchDetails');
// Device plugin is ready now
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