Skip to content

Commit

Permalink
refactor(ios)!: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
erisu committed Sep 11, 2024
1 parent bbc8c8e commit 4c1b14d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 52 deletions.
10 changes: 1 addition & 9 deletions src/ios/AppDelegate+notification.h
Original file line number Diff line number Diff line change
@@ -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) <UNUserNotificationCenterDelegate>

- (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
40 changes: 0 additions & 40 deletions src/ios/AppDelegate+notification.m
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
//
// 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;
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
Expand Down Expand Up @@ -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
11 changes: 8 additions & 3 deletions src/ios/PushPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#define GMP_NO_MODULES true

#import "PushPlugin.h"
#import "AppDelegate+notification.h"

@import Firebase;
@import FirebaseCore;
Expand Down Expand Up @@ -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];

}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -930,4 +929,10 @@ - (void)registerForRemoteNotifications
[[UIApplication sharedApplication] registerForRemoteNotifications];
}

- (void)dealloc
{
self.launchNotification = nil;
self.coldstart = nil;
}

@end

0 comments on commit 4c1b14d

Please sign in to comment.