(bug) Patch made on macOS fails to apply on Ubuntu (Codeship CI)
Hi there, this is a re-opening of #147. I have just experienced the same issue as the original poster.
I made a patch on macOS that successfully applied on multiple developers' machines. However, the patch failed to run on our Ubuntu Codeship CI.
I SSHed into the CI and made the patch again on Ubuntu, and now, this patch works on both the CI and macOS.
Take a look at the diff between the two patches. Red is macOS, green is Ubuntu.
diff --git a/patches/@react-native-firebase+messaging+12.1.0.patch b/patches/@react-native-firebase+messaging+12.1.0.patch
index 29f591e..95f354c 100644
--- a/patches/@react-native-firebase+messaging+12.1.0.patch
+++ b/patches/@react-native-firebase+messaging+12.1.0.patch
@@ -2,7 +2,7 @@ diff --git a/node_modules/@react-native-firebase/messaging/ios/RNFBMessaging/RNF
index 541114d..ef91b68 100644
--- a/node_modules/@react-native-firebase/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m
+++ b/node_modules/@react-native-firebase/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m
-@@ -69,9 +69,9 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNot
+@@ -69,9 +69,9 @@ struct {
// Don't send an event if contentAvailable is true - application:didReceiveRemoteNotification will send the event
// for us, we don't want to duplicate them
@@ -15,7 +15,7 @@ index 541114d..ef91b68 100644
// TODO in a later version allow customising completion options in JS code
completionHandler(UNNotificationPresentationOptionNone);
-@@ -88,8 +88,18 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNoti
+@@ -88,8 +88,18 @@ struct {
NSDictionary *remoteNotification = response.notification.request.content.userInfo;
if (remoteNotification[@"gcm.message_id"]) {
NSDictionary *notificationDict = [RNFBMessagingSerializer remoteMessageUserInfoToDict:remoteNotification];
I will include the full patches in the next comment.
Hypothesis
Based on the identical changes to the file but different patch result, I suppose there is an inconsistency between patch-package on the two operating systems leading to this.
Environment
The original file being patched:
https://github.com/invertase/react-native-firebase/blob/master/packages/messaging/ios/RNFBMessaging/RNFBMessaging%2BUNUserNotificationCenter.m
Note the inclusion of struct in the diff which is from much higher up in the file, around line 24.
On both operating systems I am using npx patch-package which is executing version 6.2.2.
Git version is 2.32.0 on both operating systems.
Ubuntu version:
~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.5 LTS
Release: 18.04
Codename: bionic
macOS version:
~ ยป sw_vers
ProductName: macOS
ProductVersion: 11.4
BuildVersion: 20F71
patch-package error on CI:

macOS patch:
diff --git a/node_modules/@react-native-firebase/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m b/node_modules/@react-native-firebase/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m
index 541114d..ef91b68 100644
--- a/node_modules/@react-native-firebase/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m
+++ b/node_modules/@react-native-firebase/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m
@@ -69,9 +69,9 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNot
// Don't send an event if contentAvailable is true - application:didReceiveRemoteNotification will send the event
// for us, we don't want to duplicate them
- if (!notificationDict[@"contentAvailable"]) {
- [[RNFBRCTEventEmitter shared] sendEventWithName:@"messaging_message_received" body:notificationDict];
- }
+ // this used to be wrapped in an if statement to prevent content available pushes from triggering this.
+ // patched here and removed the if(!contentAvailable) as didReceiveRemoteNotification... is no longer working (iOS 14.6).
+ [[RNFBRCTEventEmitter shared] sendEventWithName:@"messaging_message_received" body:notificationDict];
// TODO in a later version allow customising completion options in JS code
completionHandler(UNNotificationPresentationOptionNone);
@@ -88,8 +88,18 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNoti
NSDictionary *remoteNotification = response.notification.request.content.userInfo;
if (remoteNotification[@"gcm.message_id"]) {
NSDictionary *notificationDict = [RNFBMessagingSerializer remoteMessageUserInfoToDict:remoteNotification];
- [[RNFBRCTEventEmitter shared] sendEventWithName:@"messaging_notification_opened" body:notificationDict];
- _initialNotification = notificationDict;
+
+ // create a merged dictionary that will hold the serialized userInfo data, as well as any actionIdentifier
+ NSMutableDictionary * mergedDict = [NSMutableDictionary dictionary];
+
+ // copy the values of notificationDict into mergedDict
+ [mergedDict addEntriesFromDictionary:notificationDict];
+
+ // if there is an actionIdentifier on this notification, also add that in.
+ [mergedDict setObject:response.actionIdentifier forKey:@"actionIdentifier"];
+
+ [[RNFBRCTEventEmitter shared] sendEventWithName:@"messaging_notification_opened" body:mergedDict];
+ _initialNotification = mergedDict;
}
if (_originalDelegate != nil && originalDelegateRespondsTo.didReceiveNotificationResponse) {
Ubuntu patch:
diff --git a/node_modules/@react-native-firebase/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m b/node_modules/@react-native-firebase/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m
index 541114d..ef91b68 100644
--- a/node_modules/@react-native-firebase/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m
+++ b/node_modules/@react-native-firebase/messaging/ios/RNFBMessaging/RNFBMessaging+UNUserNotificationCenter.m
@@ -69,9 +69,9 @@ struct {
// Don't send an event if contentAvailable is true - application:didReceiveRemoteNotification will send the event
// for us, we don't want to duplicate them
- if (!notificationDict[@"contentAvailable"]) {
- [[RNFBRCTEventEmitter shared] sendEventWithName:@"messaging_message_received" body:notificationDict];
- }
+ // this used to be wrapped in an if statement to prevent content available pushes from triggering this.
+ // patched here and removed the if(!contentAvailable) as didReceiveRemoteNotification... is no longer working (iOS 14.6).
+ [[RNFBRCTEventEmitter shared] sendEventWithName:@"messaging_message_received" body:notificationDict];
// TODO in a later version allow customising completion options in JS code
completionHandler(UNNotificationPresentationOptionNone);
@@ -88,8 +88,18 @@ struct {
NSDictionary *remoteNotification = response.notification.request.content.userInfo;
if (remoteNotification[@"gcm.message_id"]) {
NSDictionary *notificationDict = [RNFBMessagingSerializer remoteMessageUserInfoToDict:remoteNotification];
- [[RNFBRCTEventEmitter shared] sendEventWithName:@"messaging_notification_opened" body:notificationDict];
- _initialNotification = notificationDict;
+
+ // create a merged dictionary that will hold the serialized userInfo data, as well as any actionIdentifier
+ NSMutableDictionary * mergedDict = [NSMutableDictionary dictionary];
+
+ // copy the values of notificationDict into mergedDict
+ [mergedDict addEntriesFromDictionary:notificationDict];
+
+ // if there is an actionIdentifier on this notification, also add that in.
+ [mergedDict setObject:response.actionIdentifier forKey:@"actionIdentifier"];
+
+ [[RNFBRCTEventEmitter shared] sendEventWithName:@"messaging_notification_opened" body:mergedDict];
+ _initialNotification = mergedDict;
}
if (_originalDelegate != nil && originalDelegateRespondsTo.didReceiveNotificationResponse) {
I've worked around this by doing rm -rf node_modules before each build begins, bypassing the module caching on Codeship. Then the macOS patches successfully apply on the CI.
Still not clue why the patches are created differently ๐ค