| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- /*
- * 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 "APPNotificationContent.h"
- #import "APPNotificationOptions.h"
- #import "UNUserNotificationCenter+APPLocalNotification.h"
- #import <objc/runtime.h>
- @import UserNotifications;
- static char optionsKey;
- @implementation APPNotificationContent : UNMutableNotificationContent
- #pragma mark -
- #pragma mark Init
- /**
- * Initialize a notification with the given options.
- *
- * @param [ NSDictionary* ] dict A key-value property map.
- *
- * @return [ UNMutableNotificationContent ]
- */
- - (id) initWithOptions:(NSDictionary*)dict
- {
- self = [self init];
- [self setUserInfo:dict];
- [self __init];
- return self;
- }
- /**
- * Initialize a notification by using the options found under userInfo.
- *
- * @return [ Void ]
- */
- - (void) __init
- {
- APPNotificationOptions* options = self.options;
- self.title = options.title;
- self.subtitle = options.subtitle;
- self.body = options.text;
- self.sound = options.sound;
- self.badge = options.badge;
- self.categoryIdentifier = kAPPGeneralCategory;
- }
- #pragma mark -
- #pragma mark Public
- /**
- * The options used to initialize the notification.
- *
- * @return [ APPNotificationOptions* ] options
- */
- - (APPNotificationOptions*) options
- {
- APPNotificationOptions* options = [self getOptions];
- if (!options) {
- options = [[APPNotificationOptions alloc]
- initWithDict:[self userInfo]];
- [self setOptions:options];
- }
- return options;
- }
- /**
- * The notifcations request ready to add to the notification center including
- * all informations about trigger behavior.
- *
- * @return [ UNNotificationRequest* ]
- */
- - (UNNotificationRequest*) request
- {
- APPNotificationOptions* opts = [self getOptions];
- return [UNNotificationRequest requestWithIdentifier:opts.identifier
- content:self
- trigger:opts.trigger];
- }
- #pragma mark -
- #pragma mark Private
- /**
- * The options used to initialize the notification.
- *
- * @return [ APPNotificationOptions* ]
- */
- - (APPNotificationOptions*) getOptions
- {
- return objc_getAssociatedObject(self, &optionsKey);
- }
- /**
- * Set the options used to initialize the notification.
- *
- * @param [ NSDictionary* ] dict A key-value property map.
- *
- * @return [ Void ]
- */
- - (void) setOptions:(APPNotificationOptions*)options
- {
- objc_setAssociatedObject(self, &optionsKey,
- options, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- }
- @end
|