Commit fdf8470d by Sebastián Katzer

WIP enhanced iOS10 support

parent 30da4b36
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
id="de.appplant.cordova.plugin.local-notification" id="de.appplant.cordova.plugin.local-notification"
version="0.8.4"> version="0.8.5-dev">
<name>LocalNotification</name> <name>LocalNotification</name>
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<repo>https://github.com/katzer/cordova-plugin-local-notifications.git</repo> <repo>https://github.com/katzer/cordova-plugin-local-notifications.git</repo>
<keywords>appplant, notification, local notification</keywords> <keywords>appplant, notification, local notification, user notification</keywords>
<license>Apache 2.0</license> <license>Apache 2.0</license>
...@@ -20,23 +20,15 @@ ...@@ -20,23 +20,15 @@
<!-- cordova --> <!-- cordova -->
<engines> <engines>
<engine name="cordova" version=">=3.6.0" /> <engine name="cordova" version=">=3.6.0" />
<!-- TODO next version: Probably I meant cordova-lib --> <engine name="cordova-plugman" version=">=4.3.0" />
<!-- <engine name="cordova-plugman" version=">=4.3.0" /> -->
<engine name="cordova-windows" version=">=4.2.0" /> <engine name="cordova-windows" version=">=4.2.0" />
<engine name="apple-ios" version=">=10.0.0" />
</engines> </engines>
<!-- dependencies --> <!-- dependencies -->
<dependency id="cordova-plugin-device" /> <dependency id="cordova-plugin-device" />
<dependency id="cordova-plugin-app-event" /> <dependency id="cordova-plugin-app-event" />
<!-- info -->
<info>
Your support is needed. If you use the local-notification plugin please support us in order to ensure further development.
https://github.com/katzer/cordova-plugin-local-notifications#supporting
Thank you!
</info>
<!-- js --> <!-- js -->
<js-module src="www/local-notification.js" name="LocalNotification"> <js-module src="www/local-notification.js" name="LocalNotification">
<clobbers target="cordova.plugins.notification.local" /> <clobbers target="cordova.plugins.notification.local" />
...@@ -63,17 +55,31 @@ ...@@ -63,17 +55,31 @@
</feature> </feature>
</config-file> </config-file>
<framework src="UserNotifications.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" />
<header-file src="src/ios/APPLocalNotificationOptions.h" /> <header-file src="src/ios/APPLocalNotificationOptions.h" />
<source-file src="src/ios/APPLocalNotificationOptions.m" /> <source-file src="src/ios/APPLocalNotificationOptions.m" />
<header-file src="src/ios/UIApplication+APPLocalNotification.h" /> <header-file src="src/ios/UNUserNotificationCenter+APPLocalNotification.h" />
<source-file src="src/ios/UIApplication+APPLocalNotification.m" /> <source-file src="src/ios/UNUserNotificationCenter+APPLocalNotification.m" />
<header-file src="src/ios/UNMutableNotificationContent+APPLocalNotification.h" />
<source-file src="src/ios/UNMutableNotificationContent+APPLocalNotification.m" />
<header-file src="src/ios/UNNotificationRequest+APPLocalNotification.h" />
<source-file src="src/ios/UNNotificationRequest+APPLocalNotification.m" />
<header-file src="src/ios9/APPLocalNotificationOptions.ios9.h" />
<source-file src="src/ios9/APPLocalNotificationOptions.ios9.m" />
<header-file src="src/ios9/UIApplication+APPLocalNotification.ios9.h" />
<source-file src="src/ios9/UIApplication+APPLocalNotification.ios9.m" />
<header-file src="src/ios/UILocalNotification+APPLocalNotification.h" /> <header-file src="src/ios9/UILocalNotification+APPLocalNotification.ios9.h" />
<source-file src="src/ios/UILocalNotification+APPLocalNotification.m" /> <source-file src="src/ios9/UILocalNotification+APPLocalNotification.ios9.m" />
</platform> </platform>
......
...@@ -24,7 +24,9 @@ ...@@ -24,7 +24,9 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <Cordova/CDVPlugin.h> #import <Cordova/CDVPlugin.h>
@interface APPLocalNotification : CDVPlugin @import UserNotifications;
@interface APPLocalNotification : CDVPlugin <UNUserNotificationCenterDelegate>
// Execute all queued events // Execute all queued events
- (void) deviceready:(CDVInvokedUrlCommand*)command; - (void) deviceready:(CDVInvokedUrlCommand*)command;
......
...@@ -20,7 +20,9 @@ ...@@ -20,7 +20,9 @@
* *
* @APPPLANT_LICENSE_HEADER_END@ * @APPPLANT_LICENSE_HEADER_END@
*/ */
#import <UserNotifications/UNNotificationSound.h>
#import <UserNotifications/UNNotificationRequest.h>
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
...@@ -29,14 +31,17 @@ ...@@ -29,14 +31,17 @@
- (id) initWithDict:(NSDictionary*)dict; - (id) initWithDict:(NSDictionary*)dict;
@property (readonly, getter=id) NSNumber* id; @property (readonly, getter=id) NSNumber* id;
@property (readonly, getter=badgeNumber) NSInteger badgeNumber; @property (readonly, getter=identifier) NSString* identifier;
@property (readonly, getter=alertBody) NSString* alertBody; @property (readonly, getter=title) NSString* title;
@property (readonly, getter=soundName) NSString* soundName; @property (readonly, getter=subtitle) NSString* subtitle;
@property (readonly, getter=fireDate) NSDate* fireDate; @property (readonly, getter=badge) NSNumber* badge;
@property (readonly, getter=repeatInterval) NSCalendarUnit repeatInterval; @property (readonly, getter=text) NSString* text;
@property (readonly, getter=sound) UNNotificationSound* sound;
@property (readonly, getter=userInfo) NSDictionary* userInfo; @property (readonly, getter=userInfo) NSDictionary* userInfo;
// If it's a repeating notification // If it's a repeating notification
- (BOOL) isRepeating; - (BOOL) isRepeating;
// how and when to trigger the notification
- (UNNotificationTrigger*) trigger;
@end @end
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
#import "APPLocalNotificationOptions.h" #import "APPLocalNotificationOptions.h"
// Default sound ressource path @import UserNotifications;
NSString* const DEFAULT_SOUND = @"res://platform_default";
@interface APPLocalNotificationOptions () @interface APPLocalNotificationOptions ()
...@@ -67,6 +66,14 @@ NSString* const DEFAULT_SOUND = @"res://platform_default"; ...@@ -67,6 +66,14 @@ NSString* const DEFAULT_SOUND = @"res://platform_default";
} }
/** /**
* The notification's ID as a string.
*/
- (NSString*) identifier
{
return [NSString stringWithFormat:@"%@", self.id];
}
/**
* The notification's title. * The notification's title.
*/ */
- (NSString*) title - (NSString*) title
...@@ -75,63 +82,53 @@ NSString* const DEFAULT_SOUND = @"res://platform_default"; ...@@ -75,63 +82,53 @@ NSString* const DEFAULT_SOUND = @"res://platform_default";
} }
/** /**
* The notification's message. * The notification's title.
*/ */
- (NSString*) text - (NSString*) subtitle
{ {
return [dict objectForKey:@"text"]; NSArray *parts = [self.title componentsSeparatedByString:@"\n"];
return parts.count < 2 ? @"" : [parts objectAtIndex:1];
} }
/** /**
* The notification's badge number. * The notification's message.
*/ */
- (NSInteger) badgeNumber - (NSString*) text
{ {
return [[dict objectForKey:@"badge"] intValue]; return [dict objectForKey:@"text"];
} }
#pragma mark -
#pragma mark Complex Attributes
/** /**
* The notification's alert body. * The notification's badge number.
*/ */
- (NSString*) alertBody - (NSNumber*) badge
{ {
NSString* title = [self title]; return [NSNumber numberWithInt:[[dict objectForKey:@"badge"] intValue]];
NSString* msg = [self text];
NSString* alertBody = msg;
if (![self stringIsNullOrEmpty:title])
{
alertBody = [NSString stringWithFormat:@"%@\n%@",
title, msg];
}
return alertBody;
} }
/** /**
* The notification's sound path. * The notification's sound path.
*/ */
- (NSString*) soundName - (UNNotificationSound*) sound
{ {
NSString* path = [dict objectForKey:@"sound"]; NSString* path = [dict objectForKey:@"sound"];
NSString* file;
if ([self stringIsNullOrEmpty:path]) if ([self stringIsNullOrEmpty:path])
return NULL; return NULL;
if ([path isEqualToString:DEFAULT_SOUND]) if ([path isEqualToString:@"res://platform_default"])
return UILocalNotificationDefaultSoundName; return [UNNotificationSound defaultSound];
if ([path hasPrefix:@"file:/"]) if ([path hasPrefix:@"file:/"]) {
return [self soundNameForAsset:path]; file = [self soundNameForAsset:path];
} else
if ([path hasPrefix:@"res:"]) if ([path hasPrefix:@"res:"]) {
return [self soundNameForResource:path]; file = [self soundNameForResource:path];
}
return NULL; return [UNNotificationSound soundNamed:file];
} }
/** /**
...@@ -146,47 +143,27 @@ NSString* const DEFAULT_SOUND = @"res://platform_default"; ...@@ -146,47 +143,27 @@ NSString* const DEFAULT_SOUND = @"res://platform_default";
} }
/** /**
* The notification's repeat interval. * If it's a repeating notification.
*/ */
- (NSCalendarUnit) repeatInterval - (BOOL) isRepeating
{ {
NSString* interval = [dict objectForKey:@"every"]; NSString* interval = [dict objectForKey:@"every"];
if ([self stringIsNullOrEmpty:interval]) { return ![self stringIsNullOrEmpty:interval];
return NSCalendarUnitEra;
}
else if ([interval isEqualToString:@"second"]) {
return NSCalendarUnitSecond;
}
else if ([interval isEqualToString:@"minute"]) {
return NSCalendarUnitMinute;
}
else if ([interval isEqualToString:@"hour"]) {
return NSCalendarUnitHour;
}
else if ([interval isEqualToString:@"day"]) {
return NSCalendarUnitDay;
}
else if ([interval isEqualToString:@"week"]) {
return NSCalendarUnitWeekOfYear;
}
else if ([interval isEqualToString:@"month"]) {
return NSCalendarUnitMonth;
}
else if ([interval isEqualToString:@"quarter"]) {
return NSCalendarUnitQuarter;
}
else if ([interval isEqualToString:@"year"]) {
return NSCalendarUnitYear;
}
return NSCalendarUnitEra;
} }
#pragma mark - #pragma mark -
#pragma mark Methods #pragma mark Methods
/** /**
* Specify how and when to trigger the notification.
*/
- (UNNotificationTrigger*) trigger
{
return [self isRepeating] ? [self triggerWithDateMatchingComponents] : [self triggerWithTimeInterval];
}
/**
* The notification's user info dict. * The notification's user info dict.
*/ */
- (NSDictionary*) userInfo - (NSDictionary*) userInfo
...@@ -202,18 +179,79 @@ NSString* const DEFAULT_SOUND = @"res://platform_default"; ...@@ -202,18 +179,79 @@ NSString* const DEFAULT_SOUND = @"res://platform_default";
return dict; return dict;
} }
#pragma mark -
#pragma mark Private
/** /**
* If it's a repeating notification. * Returns a trigger based on a custom time interval in seconds.
*/ */
- (BOOL) isRepeating - (UNTimeIntervalNotificationTrigger*) triggerWithTimeInterval
{ {
NSCalendarUnit interval = self.repeatInterval; return [UNTimeIntervalNotificationTrigger
triggerWithTimeInterval:[self timeInterval] repeats:NO];
}
/**
* Returns a trigger based on a calendar time.
*/
- (UNCalendarNotificationTrigger*) triggerWithDateMatchingComponents
{
NSCalendar* cal = [[NSCalendar alloc]
initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *date = [cal components:[self repeatInterval]
fromDate:[self fireDate]];
return !(interval == NSCalendarUnitEra || interval == 0); [date setTimeZone:[NSTimeZone defaultTimeZone]];
return [UNCalendarNotificationTrigger
triggerWithDateMatchingComponents:date repeats:YES];
} }
#pragma mark - /**
#pragma mark Helpers * Timeinterval between future fire date and now.
*/
- (double) timeInterval
{
return MAX(0.01f, [self.fireDate timeIntervalSinceDate:[NSDate date]]);
}
/**
* The notification's repeat interval.
*/
- (NSCalendarUnit) repeatInterval
{
NSString* interval = [dict objectForKey:@"every"];
NSCalendarUnit unitFlags = NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond;
if ([self stringIsNullOrEmpty:interval]) {
return unitFlags;
}
else if ([interval isEqualToString:@"second"]) {
return NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay;
}
else if ([interval isEqualToString:@"minute"]) {
return NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitSecond;
}
else if ([interval isEqualToString:@"hour"]) {
return NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitMinute;
}
else if ([interval isEqualToString:@"day"]) {
return NSCalendarUnitHour|NSCalendarUnitMinute;
}
else if ([interval isEqualToString:@"week"]) {
return NSCalendarUnitWeekday|NSCalendarUnitHour|NSCalendarUnitMinute;
}
else if ([interval isEqualToString:@"month"]) {
return NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute;
}
else if ([interval isEqualToString:@"year"]) {
return NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute;
}
return unitFlags;
}
/** /**
* Convert relative path to valid sound name attribute. * Convert relative path to valid sound name attribute.
...@@ -237,13 +275,7 @@ NSString* const DEFAULT_SOUND = @"res://platform_default"; ...@@ -237,13 +275,7 @@ NSString* const DEFAULT_SOUND = @"res://platform_default";
*/ */
- (BOOL) stringIsNullOrEmpty:(NSString*)str - (BOOL) stringIsNullOrEmpty:(NSString*)str
{ {
if (str == (NSString*)[NSNull null]) return (!str.length);
return YES;
if ([str isEqualToString:@""])
return YES;
return NO;
} }
@end @end
/*
* 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
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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 "APPLocalNotificationOptions.h"
@import UserNotifications;
@interface UNMutableNotificationContent (APPLocalNotification)
// Initialize a new local notification
- (id) initWithOptions:(NSDictionary*)dict;
// The options provided by the plug-in
- (APPLocalNotificationOptions*) options;
// Fully configured request to add the notification to the notification center
- (UNNotificationRequest*) request;
// Encode the user info dict to JSON
- (NSString*) encodeToJSON;
@end
/*
* 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
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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 "UNMutableNotificationContent+APPLocalNotification.h"
#import "APPLocalNotificationOptions.h"
#import <objc/runtime.h>
@import UserNotifications;
static char optionsKey;
@implementation UNMutableNotificationContent (APPLocalNotification)
#pragma mark -
#pragma mark Init
/**
* Initialize a local notification with the given options when calling on JS side:
* notification.local.add(options)
*/
- (id) initWithOptions:(NSDictionary*)dict
{
self = [self init];
[self setUserInfo:dict];
[self __init];
return self;
}
/**
* Applies the given options when calling on JS side:
* notification.local.add(options)
*/
- (void) __init
{
APPLocalNotificationOptions* options = self.options;
self.title = options.title;
self.subtitle = options.subtitle;
self.body = options.text;
self.sound = options.sound;
self.badge = options.badge;
}
#pragma mark -
#pragma mark Methods
/**
* The options provided by the plug-in.
*/
- (APPLocalNotificationOptions*) options
{
APPLocalNotificationOptions* options = [self getOptions];
if (!options) {
options = [[APPLocalNotificationOptions alloc]
initWithDict:[self userInfo]];
[self setOptions:options];
}
return options;
}
/**
* Get associated option object
*/
- (APPLocalNotificationOptions*) getOptions
{
return objc_getAssociatedObject(self, &optionsKey);
}
/**
* Set associated option object
*/
- (void) setOptions:(APPLocalNotificationOptions*)options
{
objc_setAssociatedObject(self, &optionsKey,
options, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
/**
* The notifcations request ready to add to the notification center including
* all informations about trigger behavior.
*/
- (UNNotificationRequest*) request
{
APPLocalNotificationOptions* opts = [self getOptions];
return [UNNotificationRequest requestWithIdentifier:opts.identifier
content:self
trigger:opts.trigger];
}
/**
* Encode the user info dict to JSON.
*/
- (NSString*) encodeToJSON
{
NSString* json;
NSData* data;
NSMutableDictionary* obj = [self.userInfo mutableCopy];
[obj removeObjectForKey:@"updatedAt"];
if (obj == NULL || obj.count == 0)
return json;
data = [NSJSONSerialization dataWithJSONObject:obj
options:NSJSONWritingPrettyPrinted
error:NULL];
json = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
return [json stringByReplacingOccurrencesOfString:@"\n"
withString:@""];
}
@end
/*
* 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
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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 UserNotifications;
@interface UNNotificationRequest (APPLocalNotification)
// The options provided by the plug-in
- (APPLocalNotificationOptions*) options;
// Encode the user info dict to JSON
- (NSString*) encodeToJSON;
@end
/*
* 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
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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 "UNMutableNotificationContent+APPLocalNotification.h"
#import "APPLocalNotificationOptions.h"
#import "UNNotificationRequest+APPLocalNotification.h"
#import <objc/runtime.h>
@import UserNotifications;
static char optionsKey;
@implementation UNNotificationRequest (APPLocalNotification)
/**
* Get associated option object
*/
- (APPLocalNotificationOptions*) getOptions
{
return objc_getAssociatedObject(self, &optionsKey);
}
/**
* Set associated option object
*/
- (void) setOptions:(APPLocalNotificationOptions*)options
{
objc_setAssociatedObject(self, &optionsKey,
options, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
/**
* The options provided by the plug-in.
*/
- (APPLocalNotificationOptions*) options
{
APPLocalNotificationOptions* options = [self getOptions];
if (!options) {
options = [[APPLocalNotificationOptions alloc]
initWithDict:[self.content userInfo]];
[self setOptions:options];
}
return options;
}
/**
* Encode the user info dict to JSON.
*/
- (NSString*) encodeToJSON
{
NSString* json;
NSData* data;
NSMutableDictionary* obj = [self.content.userInfo mutableCopy];
[obj removeObjectForKey:@"updatedAt"];
if (obj == NULL || obj.count == 0)
return json;
data = [NSJSONSerialization dataWithJSONObject:obj
options:NSJSONWritingPrettyPrinted
error:NULL];
json = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
return [json stringByReplacingOccurrencesOfString:@"\n"
withString:@""];
}
@end
/*
* 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
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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 "UNMutableNotificationContent+APPLocalNotification.h"
@interface UNUserNotificationCenter (APPLocalNotification)
typedef NS_ENUM(NSUInteger, APPNotificationType) {
NotifcationTypeAll = 0,
NotifcationTypeScheduled = 1,
NotifcationTypeTriggered = 2
};
#define APPNotificationType_DEFINED
@property (readonly, getter=getNotifications) NSArray* localNotifications;
@property (readonly, getter=getNotificationIds) NSArray* localNotificationIds;
// List of all notification IDs from given type
- (NSArray*) getNotificationIdsByType:(APPNotificationType)type;
// Find out if notification with ID exists
- (BOOL) notificationExist:(NSNumber*)id;
// Find out if notification with ID and type exists
- (BOOL) notificationExist:(NSNumber*)id type:(APPNotificationType)type;
// Find notification by ID
- (UNNotificationRequest*) getNotificationWithId:(NSNumber*)id;
// Find notification by ID and type
- (UNNotificationRequest*) getNotificationWithId:(NSNumber*)id andType:(APPNotificationType)type;
// Property list from all local notifications
- (NSArray*) getNotificationOptions;
// Property list from given local notifications
- (NSArray*) getNotificationOptionsById:(NSArray*)ids;
// Property list from all local notifications with type constraint
- (NSArray*) getNotificationOptionsByType:(APPNotificationType)type;
// Property list from given local notifications with type constraint
- (NSArray*) getNotificationOptionsByType:(APPNotificationType)type andId:(NSArray*)ids;
// Clear specified notfication
- (void) clearNotification:(UNNotificationRequest*)notification;
// Clear all notfications
- (void) clearAllNotifications;
// Cancel specified notfication
- (void) cancelNotification:(UNNotificationRequest*)notification;
// Cancel all notfications
- (void) cancelAllNotifications;
@end
/*
* 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
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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 "UNUserNotificationCenter+APPLocalNotification.h"
#import "UNNotificationRequest+APPLocalNotification.h"
@import UserNotifications;
@implementation UNUserNotificationCenter (APPLocalNotification)
#pragma mark -
#pragma mark LocalNotifications
/**
* List of all delivered or still pending notifications.
*/
- (NSArray*) getNotifications
{
NSMutableArray* notifications = [[NSMutableArray alloc] init];
[notifications addObjectsFromArray:[self getPendingNotifications]];
[notifications addObjectsFromArray:[self getDeliveredNotifications]];
return notifications;
}
/**
* List of all triggered notifications.
*/
- (NSArray*) getDeliveredNotifications
{
NSMutableArray* notifications = [[NSMutableArray alloc] init];
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
[self getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> *delivered) {
for (UNNotification* notification in delivered) {
[notifications addObject:notification.request];
}
dispatch_semaphore_signal(sema);
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
return notifications;
}
/**
* List of all pending notifications.
*/
- (NSArray*) getPendingNotifications
{
NSMutableArray* notifications = [[NSMutableArray alloc] init];
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
[self getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> *requests) {
[notifications addObjectsFromArray:requests];
dispatch_semaphore_signal(sema);
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
return notifications;
}
/**
* List of all notifications from given type.
*
* @param type
* Notification life cycle type
*/
- (NSArray*) getNotificationsByType:(APPNotificationType)type
{
switch (type) {
case NotifcationTypeScheduled:
return [self getPendingNotifications];
case NotifcationTypeTriggered:
return [self getDeliveredNotifications];
default:
return [self getNotifications];
}
}
/**
* List of all local notifications IDs.
*/
- (NSArray*) getNotificationIds
{
NSArray* notifications = [self getNotifications];
NSMutableArray* ids = [[NSMutableArray alloc] init];
for (UNNotificationRequest* notification in notifications)
{
[ids addObject:notification.options.id];
}
return ids;
}
/**
* List of all notifications IDs from given type.
*
* @param type
* Notification life cycle type
*/
- (NSArray*) getNotificationIdsByType:(APPNotificationType)type
{
NSArray* notifications = [self getNotificationsByType:type];
NSMutableArray* ids = [[NSMutableArray alloc] init];
for (UNNotificationRequest* notification in notifications)
{
[ids addObject:notification.options.id];
}
return ids;
}
/*
* If the notification with the specified ID does exists.
*
* @param id
* Notification ID
*/
- (BOOL) notificationExist:(NSNumber*)id
{
return [self getNotificationWithId:id] != NULL;
}
/* If the notification with specified ID and type exists.
*
* @param id
* Notification ID
* @param type
* Notification life cycle type
*/
- (BOOL) notificationExist:(NSNumber*)id type:(APPNotificationType)type
{
return [self getNotificationWithId:id andType:type] != NULL;
}
/**
* Find notification by ID.
*
* @param id
* Notification ID
*/
- (UNNotificationRequest*) getNotificationWithId:(NSNumber*)id
{
return [self getNotificationWithId:id andType:NotifcationTypeAll];
}
/*
* Find notification by ID and type.
*
* @param id
* Notification ID
* @param type
* Notification life cycle type
*/
- (UNNotificationRequest*) getNotificationWithId:(NSNumber*)id andType:(APPNotificationType)type
{
NSArray* notifications = [self getNotificationsByType:type];
for (UNNotificationRequest* notification in notifications)
{
NSString* fid = [NSString stringWithFormat:@"%@", notification.options.id];
if ([fid isEqualToString:[id stringValue]]) {
return notification;
}
}
return NULL;
}
/**
* List of properties from all notifications.
*/
- (NSArray*) getNotificationOptions
{
return [self getNotificationOptionsByType:NotifcationTypeAll];
}
/**
* List of properties from all notifications of given type.
*
* @param type
* Notification life cycle type
*/
- (NSArray*) getNotificationOptionsByType:(APPNotificationType)type
{
NSArray* notifications = [self getNotificationsByType:type];
NSMutableArray* options = [[NSMutableArray alloc] init];
for (UNNotificationRequest* notification in notifications)
{
[options addObject:notification.options.userInfo];
}
return options;
}
/**
* List of properties from given local notifications.
*
* @param ids
* Notification IDs
*/
- (NSArray*) getNotificationOptionsById:(NSArray*)ids
{
return [self getNotificationOptionsByType:NotifcationTypeAll andId:ids];
}
/**
* List of properties from given local notifications.
*
* @param type
* Notification life cycle type
* @param ids
* Notification IDs
*/
- (NSArray*) getNotificationOptionsByType:(APPNotificationType)type andId:(NSArray*)ids
{
NSArray* notifications = [self getNotificationsByType:type];
NSMutableArray* options = [[NSMutableArray alloc] init];
for (UNNotificationRequest* notification in notifications)
{
if ([ids containsObject:notification.options.id]) {
[options addObject:notification.options.userInfo];
}
}
return options;
}
/*
* Clear all notfications.
*/
- (void) clearAllNotifications
{
[self removeAllDeliveredNotifications];
}
/*
* Clear Specified notfication.
*
* @param notification
* The notification object
*/
- (void) clearNotification:(UNNotificationRequest*)notification
{
NSArray* ids = [[NSArray alloc]
initWithObjects:notification.identifier, nil];
[self removeDeliveredNotificationsWithIdentifiers:ids];
}
/*
* Cancel all notfications.
*/
- (void) cancelAllNotifications
{
[self removeAllPendingNotificationRequests];
[self removeAllDeliveredNotifications];
}
/*
* Cancel specified notfication.
*
* @param notification
* The notification object
*/
- (void) cancelNotification:(UNNotificationRequest*)notification
{
NSArray* ids = [[NSArray alloc]
initWithObjects:notification.identifier, nil];
[self removeDeliveredNotificationsWithIdentifiers:ids];
[self removePendingNotificationRequestsWithIdentifiers:ids];
}
@end
/*
* 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
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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 <Foundation/Foundation.h>
#import <Cordova/CDVPlugin.h>
@interface APPLocalNotification9 : CDVPlugin
// Execute all queued events
- (void) deviceready:(CDVInvokedUrlCommand*)command;
// Inform if the app has the permission to show notifications
- (void) hasPermission:(CDVInvokedUrlCommand*)command;
// Register permission to show notifications
- (void) registerPermission:(CDVInvokedUrlCommand*)command;
// Schedule set of notifications
- (void) schedule:(CDVInvokedUrlCommand*)command;
// Update set of notifications
- (void) update:(CDVInvokedUrlCommand*)command;
// Cancel set of notifications
- (void) cancel:(CDVInvokedUrlCommand*)command;
// Cancel all notifications
- (void) cancelAll:(CDVInvokedUrlCommand*)command;
// Clear set of notifications
- (void) clear:(CDVInvokedUrlCommand*)command;
// Clear all notifications
- (void) clearAll:(CDVInvokedUrlCommand*)command;
// If a notification with an ID is present
- (void) isPresent:(CDVInvokedUrlCommand*)command;
// If a notification with an ID is scheduled
- (void) isScheduled:(CDVInvokedUrlCommand*)command;
// If a notification with an ID is triggered
- (void) isTriggered:(CDVInvokedUrlCommand*)command;
// List all ids from all local notifications
- (void) getAllIds:(CDVInvokedUrlCommand*)command;
// List all ids from all pending notifications
- (void) getScheduledIds:(CDVInvokedUrlCommand*)command;
// List all ids from all triggered notifications
- (void) getTriggeredIds:(CDVInvokedUrlCommand*)command;
// Propertys for given local notification
- (void) getSingle:(CDVInvokedUrlCommand*)command;
// Propertya for given scheduled notification
- (void) getSingleScheduled:(CDVInvokedUrlCommand*)command;
// Propertys for given triggered notification
- (void) getSingleTriggered:(CDVInvokedUrlCommand*)command;
// Property list for given local notifications
- (void) getAll:(CDVInvokedUrlCommand*)command;
// Property list for given scheduled notifications
- (void) getScheduled:(CDVInvokedUrlCommand*)command;
// Property list for given triggered notifications
- (void) getTriggered:(CDVInvokedUrlCommand*)command;
@end
/*
* 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
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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 <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface APPLocalNotificationOptions9 : NSObject
- (id) initWithDict:(NSDictionary*)dict;
@property (readonly, getter=id) NSNumber* id;
@property (readonly, getter=badgeNumber) NSInteger badgeNumber;
@property (readonly, getter=alertBody) NSString* alertBody;
@property (readonly, getter=soundName) NSString* soundName;
@property (readonly, getter=fireDate) NSDate* fireDate;
@property (readonly, getter=repeatInterval) NSCalendarUnit repeatInterval;
@property (readonly, getter=userInfo) NSDictionary* userInfo;
// If it's a repeating notification
- (BOOL) isRepeating;
@end
/*
* 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
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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 "APPLocalNotificationOptions.ios9.h"
@interface APPLocalNotificationOptions9 ()
// The dictionary which contains all notification properties
@property(nonatomic, retain) NSDictionary* dict;
@end
@implementation APPLocalNotificationOptions9
@synthesize dict;
#pragma mark -
#pragma mark Initialization
/**
* Initialize the object with the given options when calling on JS side:
* notification.local.add(options)
*/
- (id) initWithDict:(NSDictionary*)dictionary
{
self = [self init];
self.dict = dictionary;
return self;
}
#pragma mark -
#pragma mark Attributes
/**
* The notification's ID.
*/
- (NSNumber*) id
{
NSInteger id = [[dict objectForKey:@"id"] integerValue];
return [NSNumber numberWithInteger:id];
}
/**
* The notification's title.
*/
- (NSString*) title
{
return [dict objectForKey:@"title"];
}
/**
* The notification's message.
*/
- (NSString*) text
{
return [dict objectForKey:@"text"];
}
/**
* The notification's badge number.
*/
- (NSInteger) badgeNumber
{
return [[dict objectForKey:@"badge"] intValue];
}
#pragma mark -
#pragma mark Complex Attributes
/**
* The notification's alert body.
*/
- (NSString*) alertBody
{
NSString* title = [self title];
NSString* msg = [self text];
NSString* alertBody = msg;
if (![self stringIsNullOrEmpty:title])
{
alertBody = [NSString stringWithFormat:@"%@\n%@",
title, msg];
}
return alertBody;
}
/**
* The notification's sound path.
*/
- (NSString*) soundName
{
NSString* path = [dict objectForKey:@"sound"];
if ([self stringIsNullOrEmpty:path])
return NULL;
if ([path isEqualToString:@"res://platform_default"])
return UILocalNotificationDefaultSoundName;
if ([path hasPrefix:@"file:/"])
return [self soundNameForAsset:path];
if ([path hasPrefix:@"res:"])
return [self soundNameForResource:path];
return NULL;
}
/**
* The notification's fire date.
*/
- (NSDate*) fireDate
{
double timestamp = [[dict objectForKey:@"at"]
doubleValue];
return [NSDate dateWithTimeIntervalSince1970:timestamp];
}
/**
* The notification's repeat interval.
*/
- (NSCalendarUnit) repeatInterval
{
NSString* interval = [dict objectForKey:@"every"];
if ([self stringIsNullOrEmpty:interval]) {
return NSCalendarUnitEra;
}
else if ([interval isEqualToString:@"second"]) {
return NSCalendarUnitSecond;
}
else if ([interval isEqualToString:@"minute"]) {
return NSCalendarUnitMinute;
}
else if ([interval isEqualToString:@"hour"]) {
return NSCalendarUnitHour;
}
else if ([interval isEqualToString:@"day"]) {
return NSCalendarUnitDay;
}
else if ([interval isEqualToString:@"week"]) {
return NSCalendarUnitWeekOfYear;
}
else if ([interval isEqualToString:@"month"]) {
return NSCalendarUnitMonth;
}
else if ([interval isEqualToString:@"quarter"]) {
return NSCalendarUnitQuarter;
}
else if ([interval isEqualToString:@"year"]) {
return NSCalendarUnitYear;
}
return NSCalendarUnitEra;
}
#pragma mark -
#pragma mark Methods
/**
* The notification's user info dict.
*/
- (NSDictionary*) userInfo
{
if ([dict objectForKey:@"updatedAt"]) {
NSMutableDictionary* data = [dict mutableCopy];
[data removeObjectForKey:@"updatedAt"];
return data;
}
return dict;
}
/**
* If it's a repeating notification.
*/
- (BOOL) isRepeating
{
NSCalendarUnit interval = self.repeatInterval;
return !(interval == NSCalendarUnitEra || interval == 0);
}
#pragma mark -
#pragma mark Helpers
/**
* Convert relative path to valid sound name attribute.
*/
- (NSString*) soundNameForAsset:(NSString*)path
{
return [path stringByReplacingOccurrencesOfString:@"file:/"
withString:@"www"];
}
/**
* Convert resource path to valid sound name attribute.
*/
- (NSString*) soundNameForResource:(NSString*)path
{
return [path pathComponents].lastObject;
}
/**
* If the string is empty.
*/
- (BOOL) stringIsNullOrEmpty:(NSString*)str
{
if (str == (NSString*)[NSNull null])
return YES;
if ([str isEqualToString:@""])
return YES;
return NO;
}
@end
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
* @APPPLANT_LICENSE_HEADER_END@ * @APPPLANT_LICENSE_HEADER_END@
*/ */
#import "UILocalNotification+APPLocalNotification.h" #import "UILocalNotification+APPLocalNotification.ios9.h"
@interface UIApplication (APPLocalNotification) @interface UIApplication (APPLocalNotification)
...@@ -34,26 +34,26 @@ ...@@ -34,26 +34,26 @@
- (void) registerPermissionToScheduleLocalNotifications; - (void) registerPermissionToScheduleLocalNotifications;
// List of all local notification IDs from given type // List of all local notification IDs from given type
- (NSArray*) localNotificationIdsByType:(APPLocalNotificationType)type; - (NSArray*) localNotificationIdsByType:(APPNotificationType)type;
// If local notification with ID exists // If local notification with ID exists
- (BOOL) localNotificationExist:(NSNumber*)id; - (BOOL) localNotificationExist:(NSNumber*)id;
// If local notification with ID and type exists // If local notification with ID and type exists
- (BOOL) localNotificationExist:(NSNumber*)id type:(APPLocalNotificationType)type; - (BOOL) localNotificationExist:(NSNumber*)id type:(APPNotificationType)type;
// Local notification by ID // Local notification by ID
- (UILocalNotification*) localNotificationWithId:(NSNumber*)id; - (UILocalNotification*) localNotificationWithId:(NSNumber*)id;
// Local notification by ID and type // Local notification by ID and type
- (UILocalNotification*) localNotificationWithId:(NSNumber*)id andType:(APPLocalNotificationType)type; - (UILocalNotification*) localNotificationWithId:(NSNumber*)id andType:(APPNotificationType)type;
// Property list from all local notifications // Property list from all local notifications
- (NSArray*) localNotificationOptions; - (NSArray*) localNotificationOptions;
// Property list from given local notifications // Property list from given local notifications
- (NSArray*) localNotificationOptionsById:(NSArray*)ids; - (NSArray*) localNotificationOptionsById:(NSArray*)ids;
// Property list from all local notifications with type constraint // Property list from all local notifications with type constraint
- (NSArray*) localNotificationOptionsByType:(APPLocalNotificationType)type; - (NSArray*) localNotificationOptionsByType:(APPNotificationType)type;
// Property list from given local notifications with type constraint // Property list from given local notifications with type constraint
- (NSArray*) localNotificationOptionsByType:(APPLocalNotificationType)type andId:(NSArray*)ids; - (NSArray*) localNotificationOptionsByType:(APPNotificationType)type andId:(NSArray*)ids;
// Clear single local notfications // Clear single local notfications
- (void) clearLocalNotification:(UILocalNotification*)notification; - (void) clearLocalNotification:(UILocalNotification*)notification;
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
* @APPPLANT_LICENSE_HEADER_END@ * @APPPLANT_LICENSE_HEADER_END@
*/ */
#import "UIApplication+APPLocalNotification.h" #import "UIApplication+APPLocalNotification.ios9.h"
#import "UILocalNotification+APPLocalNotification.h" #import "UILocalNotification+APPLocalNotification.ios9.h"
@implementation UIApplication (APPLocalNotification) @implementation UIApplication (APPLocalNotification)
...@@ -138,7 +138,7 @@ ...@@ -138,7 +138,7 @@
* @param type * @param type
* Notification life cycle type * Notification life cycle type
*/ */
- (NSArray*) localNotificationIdsByType:(APPLocalNotificationType)type - (NSArray*) localNotificationIdsByType:(APPNotificationType)type
{ {
NSArray* notifications = self.localNotifications; NSArray* notifications = self.localNotifications;
NSMutableArray* ids = [[NSMutableArray alloc] init]; NSMutableArray* ids = [[NSMutableArray alloc] init];
...@@ -171,7 +171,7 @@ ...@@ -171,7 +171,7 @@
* @param type * @param type
* Notification life cycle type * Notification life cycle type
*/ */
- (BOOL) localNotificationExist:(NSNumber*)id type:(APPLocalNotificationType)type - (BOOL) localNotificationExist:(NSNumber*)id type:(APPNotificationType)type
{ {
return [self localNotificationWithId:id andType:type] != NULL; return [self localNotificationWithId:id andType:type] != NULL;
} }
...@@ -206,7 +206,7 @@ ...@@ -206,7 +206,7 @@
* @param type * @param type
* Notification life cycle type * Notification life cycle type
*/ */
- (UILocalNotification*) localNotificationWithId:(NSNumber*)id andType:(APPLocalNotificationType)type - (UILocalNotification*) localNotificationWithId:(NSNumber*)id andType:(APPNotificationType)type
{ {
UILocalNotification* notification = [self localNotificationWithId:id]; UILocalNotification* notification = [self localNotificationWithId:id];
...@@ -238,7 +238,7 @@ ...@@ -238,7 +238,7 @@
* @param type * @param type
* Notification life cycle type * Notification life cycle type
*/ */
- (NSArray*) localNotificationOptionsByType:(APPLocalNotificationType)type - (NSArray*) localNotificationOptionsByType:(APPNotificationType)type
{ {
NSArray* notifications = self.localNotifications; NSArray* notifications = self.localNotifications;
NSMutableArray* options = [[NSMutableArray alloc] init]; NSMutableArray* options = [[NSMutableArray alloc] init];
...@@ -284,7 +284,7 @@ ...@@ -284,7 +284,7 @@
* @param ids * @param ids
* Notification IDs * Notification IDs
*/ */
- (NSArray*) localNotificationOptionsByType:(APPLocalNotificationType)type andId:(NSArray*)ids - (NSArray*) localNotificationOptionsByType:(APPNotificationType)type andId:(NSArray*)ids
{ {
UILocalNotification* notification; UILocalNotification* notification;
NSMutableArray* options = [[NSMutableArray alloc] init]; NSMutableArray* options = [[NSMutableArray alloc] init];
......
...@@ -21,20 +21,22 @@ ...@@ -21,20 +21,22 @@
* @APPPLANT_LICENSE_HEADER_END@ * @APPPLANT_LICENSE_HEADER_END@
*/ */
#import "APPLocalNotificationOptions.h" #import "APPLocalNotificationOptions.ios9.h"
typedef NS_ENUM(NSUInteger, APPLocalNotificationType) { #ifndef APPNotificationType_DEFINED
typedef NS_ENUM(NSUInteger, APPNotificationType) {
NotifcationTypeAll = 0, NotifcationTypeAll = 0,
NotifcationTypeScheduled = 1, NotifcationTypeScheduled = 1,
NotifcationTypeTriggered = 2 NotifcationTypeTriggered = 2
}; };
#endif
@interface UILocalNotification (APPLocalNotification) @interface UILocalNotification (APPLocalNotification)
// Initialize a new local notification // Initialize a new local notification
- (id) initWithOptions:(NSDictionary*)dict; - (id) initWithOptions:(NSDictionary*)dict;
// The options provided by the plug-in // The options provided by the plug-in
- (APPLocalNotificationOptions*) options; - (APPLocalNotificationOptions9*) options;
// Timeinterval since last trigger date // Timeinterval since last trigger date
- (double) timeIntervalSinceLastTrigger; - (double) timeIntervalSinceLastTrigger;
// Timeinterval since fire date // Timeinterval since fire date
...@@ -50,7 +52,7 @@ typedef NS_ENUM(NSUInteger, APPLocalNotificationType) { ...@@ -50,7 +52,7 @@ typedef NS_ENUM(NSUInteger, APPLocalNotificationType) {
// If it's a repeating notification // If it's a repeating notification
- (BOOL) isRepeating; - (BOOL) isRepeating;
// Notifciation type // Notifciation type
- (APPLocalNotificationType) type; - (APPNotificationType) type;
// Encode the user info dict to JSON // Encode the user info dict to JSON
- (NSString*) encodeToJSON; - (NSString*) encodeToJSON;
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
* @APPPLANT_LICENSE_HEADER_END@ * @APPPLANT_LICENSE_HEADER_END@
*/ */
#import "UILocalNotification+APPLocalNotification.h" #import "UILocalNotification+APPLocalNotification.ios9.h"
#import "APPLocalNotificationOptions.h" #import "APPLocalNotificationOptions.ios9.h"
#import <objc/runtime.h> #import <objc/runtime.h>
static char optionsKey; static char optionsKey;
...@@ -56,7 +56,7 @@ NSInteger const APPLocalNotificationTypeTriggered = 2; ...@@ -56,7 +56,7 @@ NSInteger const APPLocalNotificationTypeTriggered = 2;
*/ */
- (void) __init - (void) __init
{ {
APPLocalNotificationOptions* options = self.options; APPLocalNotificationOptions9* options = self.options;
self.fireDate = options.fireDate; self.fireDate = options.fireDate;
self.timeZone = [NSTimeZone defaultTimeZone]; self.timeZone = [NSTimeZone defaultTimeZone];
...@@ -76,12 +76,12 @@ NSInteger const APPLocalNotificationTypeTriggered = 2; ...@@ -76,12 +76,12 @@ NSInteger const APPLocalNotificationTypeTriggered = 2;
/** /**
* The options provided by the plug-in. * The options provided by the plug-in.
*/ */
- (APPLocalNotificationOptions*) options - (APPLocalNotificationOptions9*) options
{ {
APPLocalNotificationOptions* options = [self getOptions]; APPLocalNotificationOptions9* options = [self getOptions];
if (!options) { if (!options) {
options = [[APPLocalNotificationOptions alloc] options = [[APPLocalNotificationOptions9 alloc]
initWithDict:[self userInfo]]; initWithDict:[self userInfo]];
[self setOptions:options]; [self setOptions:options];
...@@ -93,7 +93,7 @@ NSInteger const APPLocalNotificationTypeTriggered = 2; ...@@ -93,7 +93,7 @@ NSInteger const APPLocalNotificationTypeTriggered = 2;
/** /**
* Get associated option object * Get associated option object
*/ */
- (APPLocalNotificationOptions*) getOptions - (APPLocalNotificationOptions9*) getOptions
{ {
return objc_getAssociatedObject(self, &optionsKey); return objc_getAssociatedObject(self, &optionsKey);
} }
...@@ -101,7 +101,7 @@ NSInteger const APPLocalNotificationTypeTriggered = 2; ...@@ -101,7 +101,7 @@ NSInteger const APPLocalNotificationTypeTriggered = 2;
/** /**
* Set associated option object * Set associated option object
*/ */
- (void) setOptions:(APPLocalNotificationOptions*)options - (void) setOptions:(APPLocalNotificationOptions9*)options
{ {
objc_setAssociatedObject(self, &optionsKey, objc_setAssociatedObject(self, &optionsKey,
options, OBJC_ASSOCIATION_RETAIN_NONATOMIC); options, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
...@@ -239,7 +239,7 @@ NSInteger const APPLocalNotificationTypeTriggered = 2; ...@@ -239,7 +239,7 @@ NSInteger const APPLocalNotificationTypeTriggered = 2;
/** /**
* Process state type of the local notification. * Process state type of the local notification.
*/ */
- (APPLocalNotificationType) type - (APPNotificationType) type
{ {
return [self isTriggered] ? NotifcationTypeTriggered : NotifcationTypeScheduled; return [self isTriggered] ? NotifcationTypeTriggered : NotifcationTypeScheduled;
} }
......
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