Skip to content

Commit

Permalink
feat!(ios): bump firebase 10.24.0 w/ improve FCM init & logging
Browse files Browse the repository at this point in the history
  • Loading branch information
erisu committed Aug 30, 2024
1 parent cc9e9c4 commit 27474eb
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 146 deletions.
3 changes: 2 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@
</platform>

<platform name="ios">
<preference name="IOS_FIREBASE_MESSAGING_VERSION" default="~> 8.1.1"/>
<preference name="IOS_FIREBASE_MESSAGING_VERSION" default="~> 10.24.0"/>

<config-file target="config.xml" parent="/*">
<feature name="PushNotification">
<param name="ios-package" value="PushPlugin"/>
<param name="onload" value="true" />
</feature>
</config-file>

Expand Down
33 changes: 16 additions & 17 deletions src/ios/AppDelegate+notification.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotif
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(@"didReceiveNotification with fetchCompletionHandler");
NSLog(@"[PushPlugin]didReceiveNotification with fetchCompletionHandler");

// app is in the background or inactive, so only call notification callback if this is a silent push
if (application.applicationState != UIApplicationStateActive) {

NSLog(@"app in-active");
NSLog(@"[PushPlugin] app in-active");

// do some convoluted logic to find out if this should be a silent push.
long silent = 0;
Expand All @@ -97,7 +97,7 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N
}

if (silent == 1) {
NSLog(@"this should be a silent push");
NSLog(@"[PushPlugin] this should be a silent push");
void (^safeHandler)(UIBackgroundFetchResult) = ^(UIBackgroundFetchResult result){
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(result);
Expand All @@ -112,19 +112,18 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N

id notId = [userInfo objectForKey:@"notId"];
if (notId != nil) {
NSLog(@"Push Plugin notId %@", notId);
NSLog(@"[PushPlugin] notId %@", notId);
[pushHandler.handlerObj setObject:safeHandler forKey:notId];
} else {
NSLog(@"Push Plugin notId handler");
NSLog(@"[PushPlugin] notId handler");
[pushHandler.handlerObj setObject:safeHandler forKey:@"handler"];
}

pushHandler.notificationMessage = userInfo;
pushHandler.isInline = NO;
[pushHandler notificationReceived];
} else {
NSLog(@"just put it in the shade");
//save it for later
NSLog(@"[PushPlugin] Save push for later");
self.launchNotification = userInfo;
completionHandler(UIBackgroundFetchResultNewData);
}
Expand Down Expand Up @@ -153,12 +152,12 @@ - (void)checkUserHasRemoteNotificationsEnabledWithCompletionHandler:(nonnull voi

- (void)pushPluginOnApplicationDidBecomeActive:(NSNotification *)notification {

NSLog(@"active");
NSLog(@"[PushPlugin] pushPluginOnApplicationDidBecomeActive");

NSString *firstLaunchKey = @"firstLaunchKey";
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"phonegap-plugin-push"];
if (![defaults boolForKey:firstLaunchKey]) {
NSLog(@"application first launch: remove badge icon number");
NSLog(@"[PushPlugin] application first launch: remove badge icon number");
[defaults setBool:YES forKey:firstLaunchKey];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
Expand All @@ -167,11 +166,11 @@ - (void)pushPluginOnApplicationDidBecomeActive:(NSNotification *)notification {

PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];
if (pushHandler.clearBadge) {
NSLog(@"PushPlugin clearing badge");
NSLog(@"[PushPlugin] clearing badge");
//zero badge
application.applicationIconBadgeNumber = 0;
} else {
NSLog(@"PushPlugin skip clear badge");
NSLog(@"[PushPlugin] skip clear badge");
}

if (self.launchNotification) {
Expand All @@ -190,7 +189,7 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
NSLog( @"NotificationCenter Handle push from foreground" );
NSLog(@"[PushPlugin] NotificationCenter Handle push from foreground");
// custom code to handle push while app is in the foreground
PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];
pushHandler.notificationMessage = notification.request.content.userInfo;
Expand All @@ -210,11 +209,11 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void(^)(void))completionHandler
{
NSLog(@"Push Plugin didReceiveNotificationResponse: actionIdentifier %@, notification: %@", response.actionIdentifier,
NSLog(@"[PushPlugin] didReceiveNotificationResponse: actionIdentifier %@, notification: %@", response.actionIdentifier,
response.notification.request.content.userInfo);
NSMutableDictionary *userInfo = [response.notification.request.content.userInfo mutableCopy];
[userInfo setObject:response.actionIdentifier forKey:@"actionCallback"];
NSLog(@"Push Plugin userInfo %@", userInfo);
NSLog(@"[PushPlugin] userInfo %@", userInfo);

switch ([UIApplication sharedApplication].applicationState) {
case UIApplicationStateActive:
Expand All @@ -228,7 +227,7 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
}
case UIApplicationStateInactive:
{
NSLog(@"coldstart");
NSLog(@"[PushPlugin] coldstart");

if([response.actionIdentifier rangeOfString:@"UNNotificationDefaultActionIdentifier"].location == NSNotFound) {
self.launchNotification = userInfo;
Expand Down Expand Up @@ -256,10 +255,10 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center

id notId = [userInfo objectForKey:@"notId"];
if (notId != nil) {
NSLog(@"Push Plugin notId %@", notId);
NSLog(@"[PushPlugin] notId %@", notId);
[pushHandler.handlerObj setObject:safeHandler forKey:notId];
} else {
NSLog(@"Push Plugin notId handler");
NSLog(@"[PushPlugin] notId handler");
[pushHandler.handlerObj setObject:safeHandler forKey:@"handler"];
}

Expand Down
4 changes: 4 additions & 0 deletions src/ios/PushPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
BOOL forceShow;

NSMutableDictionary *handlerObj;
NSMutableDictionary *iOSOptions;

void (^completionHandler)(UIBackgroundFetchResult);

BOOL ready;
Expand All @@ -55,7 +57,9 @@
@property BOOL coldstart;
@property BOOL clearBadge;
@property BOOL forceShow;

@property (nonatomic, strong) NSMutableDictionary *handlerObj;
@property (nonatomic, strong) NSMutableDictionary *iOSOptions;

- (void)init:(CDVInvokedUrlCommand*)command;
- (void)unregister:(CDVInvokedUrlCommand*)command;
Expand Down
Loading

0 comments on commit 27474eb

Please sign in to comment.