summaryrefslogtreecommitdiff
path: root/plugins/phonegap-plugin-push/src/ios
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/phonegap-plugin-push/src/ios')
-rw-r--r--plugins/phonegap-plugin-push/src/ios/AppDelegate+notification.h22
-rw-r--r--plugins/phonegap-plugin-push/src/ios/AppDelegate+notification.m135
-rw-r--r--plugins/phonegap-plugin-push/src/ios/PushPlugin.h56
-rw-r--r--plugins/phonegap-plugin-push/src/ios/PushPlugin.m279
4 files changed, 0 insertions, 492 deletions
diff --git a/plugins/phonegap-plugin-push/src/ios/AppDelegate+notification.h b/plugins/phonegap-plugin-push/src/ios/AppDelegate+notification.h
deleted file mode 100644
index 695e9384..00000000
--- a/plugins/phonegap-plugin-push/src/ios/AppDelegate+notification.h
+++ /dev/null
@@ -1,22 +0,0 @@
-//
-// AppDelegate+notification.h
-// pushtest
-//
-// Created by Robert Easterday on 10/26/12.
-//
-//
-
-#import "AppDelegate.h"
-
-@interface AppDelegate (notification)
-- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
-- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
-- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;
-- (void)applicationDidBecomeActive:(UIApplication *)application;
-- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings;
-- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler;
-- (id) getCommandInstance:(NSString*)className;
-
-@property (nonatomic, retain) NSDictionary *launchNotification;
-
-@end
diff --git a/plugins/phonegap-plugin-push/src/ios/AppDelegate+notification.m b/plugins/phonegap-plugin-push/src/ios/AppDelegate+notification.m
deleted file mode 100644
index 37241269..00000000
--- a/plugins/phonegap-plugin-push/src/ios/AppDelegate+notification.m
+++ /dev/null
@@ -1,135 +0,0 @@
-//
-// AppDelegate+notification.m
-// pushtest
-//
-// Created by Robert Easterday on 10/26/12.
-//
-//
-
-#import "AppDelegate+notification.h"
-#import "PushPlugin.h"
-#import <objc/runtime.h>
-
-static char launchNotificationKey;
-
-@implementation AppDelegate (notification)
-
-- (id) getCommandInstance:(NSString*)className
-{
- return [self.viewController getCommandInstance:className];
-}
-
-// its dangerous to override a method from within a category.
-// Instead we will use method swizzling. we set this up in the load call.
-+ (void)load
-{
- Method original, swizzled;
-
- original = class_getInstanceMethod(self, @selector(init));
- swizzled = class_getInstanceMethod(self, @selector(swizzled_init));
- method_exchangeImplementations(original, swizzled);
-}
-
-- (AppDelegate *)swizzled_init
-{
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(createNotificationChecker:)
- name:@"UIApplicationDidFinishLaunchingNotification" object:nil];
-
- // This actually calls the original init method over in AppDelegate. Equivilent to calling super
- // on an overrided method, this is not recursive, although it appears that way. neat huh?
- return [self swizzled_init];
-}
-
-// This code will be called immediately after application:didFinishLaunchingWithOptions:. We need
-// to process notifications in cold-start situations
-- (void)createNotificationChecker:(NSNotification *)notification
-{
- if (notification)
- {
- NSDictionary *launchOptions = [notification userInfo];
- if (launchOptions)
- self.launchNotification = [launchOptions objectForKey: @"UIApplicationLaunchOptionsRemoteNotificationKey"];
- }
-}
-
-- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
- PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];
- [pushHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
-}
-
-- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
- PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];
- [pushHandler didFailToRegisterForRemoteNotificationsWithError:error];
-}
-
-- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
- NSLog(@"didReceiveNotification");
-
- // Get application state for iOS4.x+ devices, otherwise assume active
- UIApplicationState appState = UIApplicationStateActive;
- if ([application respondsToSelector:@selector(applicationState)]) {
- appState = application.applicationState;
- }
-
- if (appState == UIApplicationStateActive) {
- PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];
- pushHandler.notificationMessage = userInfo;
- pushHandler.isInline = YES;
- [pushHandler notificationReceived];
- } else {
- //save it for later
- self.launchNotification = userInfo;
- }
-}
-
-- (void)applicationDidBecomeActive:(UIApplication *)application {
-
- NSLog(@"active");
-
- //zero badge
- application.applicationIconBadgeNumber = 0;
-
- if (self.launchNotification) {
- PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];
- pushHandler.isInline = NO;
- pushHandler.notificationMessage = self.launchNotification;
- self.launchNotification = nil;
- [pushHandler performSelectorOnMainThread:@selector(notificationReceived) withObject:pushHandler waitUntilDone:NO];
- }
-}
-
-- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
-{
- //register to receive notifications
- [application registerForRemoteNotifications];
-}
-
-//For interactive notification only
-- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
-{
- //handle the actions
- if ([identifier isEqualToString:@"declineAction"]){
- }
- else if ([identifier isEqualToString:@"answerAction"]){
- }
-}
-
-
-// The accessors use an Associative Reference since you can't define a iVar in a category
-// http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/objectivec/Chapters/ocAssociativeReferences.html
-- (NSMutableArray *)launchNotification
-{
- return objc_getAssociatedObject(self, &launchNotificationKey);
-}
-
-- (void)setLaunchNotification:(NSDictionary *)aDictionary
-{
- objc_setAssociatedObject(self, &launchNotificationKey, aDictionary, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
-}
-
-- (void)dealloc
-{
- self.launchNotification = nil; // clear the association and release the object
-}
-
-@end
diff --git a/plugins/phonegap-plugin-push/src/ios/PushPlugin.h b/plugins/phonegap-plugin-push/src/ios/PushPlugin.h
deleted file mode 100644
index e363e2e5..00000000
--- a/plugins/phonegap-plugin-push/src/ios/PushPlugin.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- Copyright 2009-2011 Urban Airship Inc. All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
- 2. Redistributions in binaryform must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided withthe distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE URBAN AIRSHIP INC``AS IS'' AND ANY EXPRESS OR
- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
- EVENT SHALL URBAN AIRSHIP INC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import <Foundation/Foundation.h>
-#import <Cordova/CDV.h>
-#import <Cordova/CDVPlugin.h>
-
-@interface PushPlugin : CDVPlugin
-{
- NSDictionary *notificationMessage;
- BOOL isInline;
- NSString *notificationCallbackId;
- NSString *callback;
-
- BOOL ready;
-}
-
-@property (nonatomic, copy) NSString *callbackId;
-@property (nonatomic, copy) NSString *notificationCallbackId;
-@property (nonatomic, copy) NSString *callback;
-
-@property (nonatomic, strong) NSDictionary *notificationMessage;
-@property BOOL isInline;
-
-- (void)init:(CDVInvokedUrlCommand*)command;
-- (void)unregister:(CDVInvokedUrlCommand*)command;
-
-- (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
-- (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
-
-- (void)setNotificationMessage:(NSDictionary *)notification;
-- (void)notificationReceived;
-
-@end
diff --git a/plugins/phonegap-plugin-push/src/ios/PushPlugin.m b/plugins/phonegap-plugin-push/src/ios/PushPlugin.m
deleted file mode 100644
index fc5b8c2e..00000000
--- a/plugins/phonegap-plugin-push/src/ios/PushPlugin.m
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- Copyright 2009-2011 Urban Airship Inc. All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- 1. Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
- 2. Redistributions in binaryform must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided withthe distribution.
-
- THIS SOFTWARE IS PROVIDED BY THE URBAN AIRSHIP INC``AS IS'' AND ANY EXPRESS OR
- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
- EVENT SHALL URBAN AIRSHIP INC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "PushPlugin.h"
-
-@implementation PushPlugin
-
-@synthesize notificationMessage;
-@synthesize isInline;
-
-@synthesize callbackId;
-@synthesize notificationCallbackId;
-@synthesize callback;
-
-
-- (void)unregister:(CDVInvokedUrlCommand*)command;
-{
- self.callbackId = command.callbackId;
-
- [[UIApplication sharedApplication] unregisterForRemoteNotifications];
- [self successWithMessage:@"unregistered"];
-}
-
-- (void)init:(CDVInvokedUrlCommand*)command;
-{
- NSLog(@"Push Plugin register called");
- self.callbackId = command.callbackId;
-
- NSMutableDictionary* options = [command.arguments objectAtIndex:0];
- NSMutableDictionary* iosOptions = [options objectForKey:@"ios"];
-
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
- UIUserNotificationType UserNotificationTypes = UIUserNotificationTypeNone;
-#endif
- UIRemoteNotificationType notificationTypes = UIRemoteNotificationTypeNone;
-
- id badgeArg = [iosOptions objectForKey:@"badge"];
- id soundArg = [iosOptions objectForKey:@"sound"];
- id alertArg = [iosOptions objectForKey:@"alert"];
-
- if (([badgeArg isKindOfClass:[NSString class]] && [badgeArg isEqualToString:@"true"]) || [badgeArg boolValue])
- {
- notificationTypes |= UIRemoteNotificationTypeBadge;
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
- UserNotificationTypes |= UIUserNotificationTypeBadge;
-#endif
- }
-
- if (([soundArg isKindOfClass:[NSString class]] && [soundArg isEqualToString:@"true"]) || [soundArg boolValue])
- {
- notificationTypes |= UIRemoteNotificationTypeSound;
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
- UserNotificationTypes |= UIUserNotificationTypeSound;
-#endif
- }
-
- if (([alertArg isKindOfClass:[NSString class]] && [alertArg isEqualToString:@"true"]) || [alertArg boolValue])
- {
- notificationTypes |= UIRemoteNotificationTypeAlert;
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
- UserNotificationTypes |= UIUserNotificationTypeAlert;
-#endif
- }
-
- notificationTypes |= UIRemoteNotificationTypeNewsstandContentAvailability;
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
- UserNotificationTypes |= UIUserNotificationActivationModeBackground;
-#endif
-
- if (notificationTypes == UIRemoteNotificationTypeNone)
- NSLog(@"PushPlugin.register: Push notification type is set to none");
-
- isInline = NO;
-
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
- if ([[UIApplication sharedApplication]respondsToSelector:@selector(registerUserNotificationSettings:)]) {
- UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UserNotificationTypes categories:nil];
- [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
- [[UIApplication sharedApplication] registerForRemoteNotifications];
- } else {
- [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
- (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
- }
-#else
- [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
- (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
-#endif
-
- if (notificationMessage) // if there is a pending startup notification
- [self notificationReceived]; // go ahead and process it
-}
-
-- (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
- NSLog(@"Push Plugin register success: %@", deviceToken);
-
- NSMutableDictionary *results = [NSMutableDictionary dictionary];
- NSString *token = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<"withString:@""]
- stringByReplacingOccurrencesOfString:@">" withString:@""]
- stringByReplacingOccurrencesOfString: @" " withString: @""];
- [results setValue:token forKey:@"deviceToken"];
-
-#if !TARGET_IPHONE_SIMULATOR
- // Get Bundle Info for Remote Registration (handy if you have more than one app)
- [results setValue:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"] forKey:@"appName"];
- [results setValue:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] forKey:@"appVersion"];
-
- // Check what Notifications the user has turned on. We registered for all three, but they may have manually disabled some or all of them.
-#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
-
- NSUInteger rntypes;
- if (!SYSTEM_VERSION_LESS_THAN(@"8.0")) {
- rntypes = [[[UIApplication sharedApplication] currentUserNotificationSettings] types];
- } else {
- rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
- }
-
- // Set the defaults to disabled unless we find otherwise...
- NSString *pushBadge = @"disabled";
- NSString *pushAlert = @"disabled";
- NSString *pushSound = @"disabled";
-
- // Check what Registered Types are turned on. This is a bit tricky since if two are enabled, and one is off, it will return a number 2... not telling you which
- // one is actually disabled. So we are literally checking to see if rnTypes matches what is turned on, instead of by number. The "tricky" part is that the
- // single notification types will only match if they are the ONLY one enabled. Likewise, when we are checking for a pair of notifications, it will only be
- // true if those two notifications are on. This is why the code is written this way
- if(rntypes & UIRemoteNotificationTypeBadge){
- pushBadge = @"enabled";
- }
- if(rntypes & UIRemoteNotificationTypeAlert) {
- pushAlert = @"enabled";
- }
- if(rntypes & UIRemoteNotificationTypeSound) {
- pushSound = @"enabled";
- }
-
- [results setValue:pushBadge forKey:@"pushBadge"];
- [results setValue:pushAlert forKey:@"pushAlert"];
- [results setValue:pushSound forKey:@"pushSound"];
-
- // Get the users Device Model, Display Name, Token & Version Number
- UIDevice *dev = [UIDevice currentDevice];
- [results setValue:dev.name forKey:@"deviceName"];
- [results setValue:dev.model forKey:@"deviceModel"];
- [results setValue:dev.systemVersion forKey:@"deviceSystemVersion"];
-
- // Send result to trigger 'registration' event but keep callback
- NSMutableDictionary* message = [NSMutableDictionary dictionaryWithCapacity:1];
- [message setObject:token forKey:@"registrationId"];
- CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:message];
- [pluginResult setKeepCallbackAsBool:YES];
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
-#endif
-}
-
-- (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
-{
- NSLog(@"Push Plugin register failed");
- [self failWithMessage:@"" withError:error];
-}
-
-- (void)notificationReceived {
- NSLog(@"Notification received");
-
- if (notificationMessage && self.callbackId != nil)
- {
- NSMutableDictionary* message = [NSMutableDictionary dictionaryWithCapacity:4];
- NSMutableDictionary* additionalData = [NSMutableDictionary dictionaryWithCapacity:4];
-
-
- for (id key in notificationMessage) {
- if ([key isEqualToString:@"aps"]) {
- id aps = [notificationMessage objectForKey:@"aps"];
-
- for(id key in aps) {
- NSLog(@"Push Plugin key: %@", key);
- id value = [aps objectForKey:key];
-
- if ([key isEqualToString:@"alert"]) {
- if ([value isKindOfClass:[NSDictionary class]]) {
- for (id messageKey in value) {
- id messageValue = [value objectForKey:messageKey];
- if ([messageKey isEqualToString:@"body"]) {
- [message setObject:messageValue forKey:@"message"];
- } else if ([messageKey isEqualToString:@"title"]) {
- [message setObject:messageValue forKey:@"title"];
- } else {
- [additionalData setObject:messageValue forKey:messageKey];
- }
- }
- }
- else {
- [message setObject:value forKey:@"message"];
- }
- } else if ([key isEqualToString:@"title"]) {
- [message setObject:value forKey:@"title"];
- } else if ([key isEqualToString:@"badge"]) {
- [message setObject:value forKey:@"count"];
- } else if ([key isEqualToString:@"sound"]) {
- [message setObject:value forKey:@"sound"];
- } else if ([key isEqualToString:@"image"]) {
- [message setObject:value forKey:@"image"];
- } else {
- [additionalData setObject:value forKey:key];
- }
- }
- } else {
- [additionalData setObject:[notificationMessage objectForKey:key] forKey:key];
- }
- }
-
- if (isInline) {
- [additionalData setObject:[NSNumber numberWithBool:YES] forKey:@"foreground"];
- } else {
- [additionalData setObject:[NSNumber numberWithBool:NO] forKey:@"foreground"];
- }
-
- [message setObject:additionalData forKey:@"additionalData"];
-
- // send notification message
- CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:message];
- [pluginResult setKeepCallbackAsBool:YES];
- [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
-
- self.notificationMessage = nil;
- }
-}
-
-- (void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command
-{
- NSMutableDictionary* options = [command.arguments objectAtIndex:0];
- int badge = [[options objectForKey:@"badge"] intValue] ?: 0;
-
- [[UIApplication sharedApplication] setApplicationIconBadgeNumber:badge];
-
- NSString* message = [NSString stringWithFormat:@"app badge count set to %d", badge];
- CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message];
- [self.commandDelegate sendPluginResult:commandResult callbackId:command.callbackId];
-}
-
--(void)successWithMessage:(NSString *)message
-{
- if (self.callbackId != nil)
- {
- CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message];
- [self.commandDelegate sendPluginResult:commandResult callbackId:self.callbackId];
- }
-}
-
--(void)failWithMessage:(NSString *)message withError:(NSError *)error
-{
- NSString *errorMessage = (error) ? [NSString stringWithFormat:@"%@ - %@", message, [error localizedDescription]] : message;
- CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:errorMessage];
-
- [self.commandDelegate sendPluginResult:commandResult callbackId:self.callbackId];
-}
-
-@end