From 4c1b14d266a054af3fe04dde000aba6b544ee3c8 Mon Sep 17 00:00:00 2001 From: Erisu Date: Wed, 11 Sep 2024 20:41:24 +0900 Subject: [PATCH] refactor(ios)!: cleanup --- src/ios/AppDelegate+notification.h | 10 +------- src/ios/AppDelegate+notification.m | 40 ------------------------------ src/ios/PushPlugin.m | 11 +++++--- 3 files changed, 9 insertions(+), 52 deletions(-) diff --git a/src/ios/AppDelegate+notification.h b/src/ios/AppDelegate+notification.h index 31ac4c7db..e041b52b2 100644 --- a/src/ios/AppDelegate+notification.h +++ b/src/ios/AppDelegate+notification.h @@ -1,24 +1,16 @@ // // AppDelegate+notification.h -// pushtest // // Created by Robert Easterday on 10/26/12. // -// #import "AppDelegate.h" @import UserNotifications; -extern NSString *const pushPluginApplicationDidBecomeActiveNotification; - @interface AppDelegate (notification) + - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken; - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error; - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:( void (^)(UIBackgroundFetchResult))completionHandler; -- (id) getCommandInstance:(NSString*)className; - -@property (nonatomic, retain) NSDictionary *launchNotification; -@property (nonatomic, retain) NSNumber *coldstart; - @end diff --git a/src/ios/AppDelegate+notification.m b/src/ios/AppDelegate+notification.m index 0425751b3..7a2c38d44 100644 --- a/src/ios/AppDelegate+notification.m +++ b/src/ios/AppDelegate+notification.m @@ -1,27 +1,15 @@ // // AppDelegate+notification.m -// pushtest // // Created by Robert Easterday on 10/26/12. // -// #import "AppDelegate+notification.h" #import "PushPlugin.h" #import -static char launchNotificationKey; -static char coldstartKey; -NSString *const pushPluginApplicationDidBecomeActiveNotification = @"pushPluginApplicationDidBecomeActiveNotification"; - - @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 @@ -110,32 +98,4 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNoti [NSNotificationCenter.defaultCenter postNotificationName:@"CordovaPluginPushDidReceiveNotificationResponse" object:nil userInfo:notificationInfo]; } -// 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); -} - -- (NSNumber *)coldstart -{ - return objc_getAssociatedObject(self, &coldstartKey); -} - -- (void)setColdstart:(NSNumber *)aNumber -{ - objc_setAssociatedObject(self, &coldstartKey, aNumber, OBJC_ASSOCIATION_RETAIN_NONATOMIC); -} - -- (void)dealloc -{ - self.launchNotification = nil; // clear the association and release the object - self.coldstart = nil; -} - @end diff --git a/src/ios/PushPlugin.m b/src/ios/PushPlugin.m index 192c86266..87d0080fe 100644 --- a/src/ios/PushPlugin.m +++ b/src/ios/PushPlugin.m @@ -27,7 +27,6 @@ #define GMP_NO_MODULES true #import "PushPlugin.h" -#import "AppDelegate+notification.h" @import Firebase; @import FirebaseCore; @@ -293,7 +292,7 @@ - (void)pushPluginOnApplicationDidBecomeActive:(NSNotification *)notification { [self performSelectorOnMainThread:@selector(notificationReceived) withObject:self waitUntilDone:NO]; } - [[NSNotificationCenter defaultCenter] postNotificationName:pushPluginApplicationDidBecomeActiveNotification object:nil]; + [[NSNotificationCenter defaultCenter] postNotificationName:@"CordovaPluginPushApplicationDidBecomeActiveNotification" object:nil]; } @@ -537,7 +536,7 @@ - (void)init:(CDVInvokedUrlCommand*)command; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotificationSettings:) - name:pushPluginApplicationDidBecomeActiveNotification + name:@"CordovaPluginPushApplicationDidBecomeActiveNotification" object:nil]; if(notificationMessage) { // if there is a pending startup notification @@ -930,4 +929,10 @@ - (void)registerForRemoteNotifications [[UIApplication sharedApplication] registerForRemoteNotifications]; } +- (void)dealloc +{ + self.launchNotification = nil; + self.coldstart = nil; +} + @end