Skip to content

Commit

Permalink
chore: revert back to AppDelegate (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
erisu authored Nov 19, 2024
1 parent f1ae1c2 commit 1cbc402
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@
<string>production</string>
</config-file>

<source-file src="src/ios/CDVAppDelegate+notification.m"/>
<source-file src="src/ios/AppDelegate+PushPlugin.m"/>
<source-file src="src/ios/PushPlugin.m"/>
<source-file src="src/ios/PushPluginConstants.m"/>
<source-file src="src/ios/PushPluginFCM.m"/>
<source-file src="src/ios/PushPluginSettings.m"/>

<header-file src="src/ios/CDVAppDelegate+notification.h"/>
<header-file src="src/ios/AppDelegate+PushPlugin.h"/>
<header-file src="src/ios/PushPlugin.h"/>
<source-file src="src/ios/PushPluginConstants.h"/>
<header-file src="src/ios/PushPluginFCM.h"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//
// CDVAppDelegate+notification.h
// AppDelegate+PushPlugin.h
//
// Created by Robert Easterday on 10/26/12.
//

#import <Cordova/CDVAppDelegate.h>
#import "AppDelegate.h"

@import UserNotifications;

@interface CDVAppDelegate (notification) <UNUserNotificationCenterDelegate>
@interface AppDelegate (PushPlugin) <UNUserNotificationCenterDelegate>

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//
// CDVAppDelegate+notification.m
// AppDelegate+PushPlugin.m
//
// Created by Robert Easterday on 10/26/12.
//

#import "CDVAppDelegate+notification.h"
#import "AppDelegate+PushPlugin.h"
#import "PushPlugin.h"
#import "PushPluginConstants.h"
#import <objc/runtime.h>

@implementation CDVAppDelegate (notification)
@implementation AppDelegate (PushPlugin)

// its dangerous to override a method from within a category.
// Instead we will use method swizzling. we set this up in the load call.
Expand All @@ -34,10 +34,10 @@ + (void)load {
});
}

- (CDVAppDelegate *)pushPluginSwizzledInit {
- (AppDelegate *)pushPluginSwizzledInit {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
// This actually calls the original init method over in CDVAppDelegate. Equivilent to calling super
// 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 pushPluginSwizzledInit];
}
Expand Down
5 changes: 2 additions & 3 deletions src/ios/PushPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/

#import "PushPlugin.h"
#import "CDVAppDelegate+notification.h"
#import "PushPluginConstants.h"
#import "PushPluginFCM.h"
#import "PushPluginSettings.h"
Expand Down Expand Up @@ -350,7 +349,7 @@ - (void)willPresentNotification:(NSNotification *)notification {
UIApplicationState applicationState = [UIApplication sharedApplication].applicationState;
NSNumber *applicationStateNumber = @((int)applicationState);

// The original notification that comes from the CDVAppDelegate's willPresentNotification.
// The original notification that comes from the AppDelegate's willPresentNotification.
UNNotification *originalNotification = notification.userInfo[@"notification"];
NSDictionary *originalUserInfo = originalNotification.request.content.userInfo;
NSMutableDictionary *modifiedUserInfo = [originalUserInfo mutableCopy];
Expand Down Expand Up @@ -399,7 +398,7 @@ - (void)willPresentNotification:(NSNotification *)notification {
}

- (void)didReceiveNotificationResponse:(NSNotification *)notification {
// The original response that comes from the CDVAppDelegate's didReceiveNotificationResponse.
// The original response that comes from the AppDelegate's didReceiveNotificationResponse.
UNNotificationResponse *response = notification.userInfo[@"response"];

NSLog(@"[PushPlugin] Notification was received. (actionIdentifier %@, notification: %@)",
Expand Down

0 comments on commit 1cbc402

Please sign in to comment.