Loading src/ios/AppDelegate+notification.m +34 −2 Changes for src/ios/AppDelegate+notification.m: 34 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -19,6 +19,39 @@ static char launchNotificationKey; 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:@"PushPlugin"]; [pushHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; Loading Loading @@ -58,10 +91,9 @@ static char launchNotificationKey; if (![self.viewController.webView isLoading] && self.launchNotification) { PushPlugin *pushHandler = [self getCommandInstance:@"PushPlugin"]; pushHandler.notificationMessage = self.launchNotification; pushHandler.notificationMessage = self.launchNotification; self.launchNotification = nil; [pushHandler performSelectorOnMainThread:@selector(notificationReceived) withObject:pushHandler waitUntilDone:NO]; } } Loading src/ios/PushPlugin.m +6 −1 Changes for src/ios/PushPlugin.m: 6 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -92,6 +92,9 @@ isInline = NO; [[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationTypes]; if (notificationMessage) // if there is a pending startup notification [self notificationReceived]; // go ahead and process it } - (void)isEnabled:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options { Loading Loading @@ -174,7 +177,7 @@ - (void)notificationReceived { NSLog(@"Notification received"); if (notificationMessage) if (notificationMessage && self.callback) { NSMutableString *jsonStr = [NSMutableString stringWithString:@"{"]; Loading @@ -185,6 +188,8 @@ [jsonStr appendFormat:@"foreground:'%d',", 1]; isInline = NO; } else [jsonStr appendFormat:@"foreground:'%d',", 0]; [jsonStr appendString:@"}"]; Loading Loading
src/ios/AppDelegate+notification.m +34 −2 Changes for src/ios/AppDelegate+notification.m: 34 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -19,6 +19,39 @@ static char launchNotificationKey; 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:@"PushPlugin"]; [pushHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; Loading Loading @@ -58,10 +91,9 @@ static char launchNotificationKey; if (![self.viewController.webView isLoading] && self.launchNotification) { PushPlugin *pushHandler = [self getCommandInstance:@"PushPlugin"]; pushHandler.notificationMessage = self.launchNotification; pushHandler.notificationMessage = self.launchNotification; self.launchNotification = nil; [pushHandler performSelectorOnMainThread:@selector(notificationReceived) withObject:pushHandler waitUntilDone:NO]; } } Loading
src/ios/PushPlugin.m +6 −1 Changes for src/ios/PushPlugin.m: 6 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -92,6 +92,9 @@ isInline = NO; [[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationTypes]; if (notificationMessage) // if there is a pending startup notification [self notificationReceived]; // go ahead and process it } - (void)isEnabled:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options { Loading Loading @@ -174,7 +177,7 @@ - (void)notificationReceived { NSLog(@"Notification received"); if (notificationMessage) if (notificationMessage && self.callback) { NSMutableString *jsonStr = [NSMutableString stringWithString:@"{"]; Loading @@ -185,6 +188,8 @@ [jsonStr appendFormat:@"foreground:'%d',", 1]; isInline = NO; } else [jsonStr appendFormat:@"foreground:'%d',", 0]; [jsonStr appendString:@"}"]; Loading