invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.71k stars 2.22k forks source link

[MESSAGING] IOS ONLY - v7.8.4 Clicking on notification open app then immediately crash #4192

Closed Aurelienlajoinie closed 4 years ago

Aurelienlajoinie commented 4 years ago

Hello everyone,

We are facing an issue after updating all firebase package. When we try to open notification while app is killed, the app startup and immediately crash mentionned an error in the RNFBMessagingUNUserNotificationCenter file from messaging. After some debug the problem is in the method didReceiveNotificationResponse:

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
  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;
  }

 **==== crash here !!! ====**
 if (_originalDelegate != nil && originalDelegateRespondsTo.didReceiveNotificationResponse) {
    [_originalDelegate userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
  } else {
    completionHandler();
  }
}

i quick fix the problem just by comment delegate callback and so always use "default" completionHandler:

 //if (_originalDelegate != nil && originalDelegateRespondsTo.didReceiveNotificationResponse) {
 //   [_originalDelegate userNotificationCenter:center didReceiveNotificationResponse:response //withCompletionHandler:completionHandler];
  //} else {
    completionHandler();
 // } 

I don't understand what appends because _originalDelegate and originalDelegateRespondsTo seems to be ok but the crash is here :s

Project Files

require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
require_relative '../node_modules/react-native-unimodules/cocoapods.rb'

platform :ios, '10.0'

use_frameworks!
workspace 'app.xcworkspace'

project 'app', 'Release' => :release, 'Recette Release' => :release, 'Debug' => :debug, 'Recette Debug' => :debug

def shared_pods

  pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
  pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
  pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/'
  pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
  pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
  pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
  pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
  pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
  pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
  pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
  pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
  pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
  pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
  pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
  pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'

  pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
  pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
  pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
  pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
  pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
  pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
  pod 'UMCore', :path => '../node_modules/@unimodules/core/ios'
  pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

  use_unimodules!
  use_native_modules!

  #.....

  # Unimodules (Expo)
  pod 'UMCore', path: '../node_modules/@unimodules/core/ios'
  pod 'UMReactNativeAdapter', path: '../node_modules/@unimodules/react-native-adapter/ios', inhibit_warnings: true

end

target 'app' do
  inherit! :search_paths
  shared_pods
end

target 'app-iphone' do
  inherit! :search_paths
  shared_pods
end

target 'RichNotificationExtension' do
  pod 'FANotificationExtension', '1.0.1'
end

pre_install do |installer|
  installer.pod_targets.each do |pod|
    if pod.name.start_with?('RNFB')
      def pod.build_type;
        Pod::BuildType.static_library
      end
    end
  end
end

package.json:

    "@react-native-firebase/analytics": "7.6.1",
    "@react-native-firebase/app": "8.4.1",
    "@react-native-firebase/crashlytics": "8.4.2",
    "@react-native-firebase/messaging":"7.8.4",
    "@react-native-firebase/perf": "7.4.2",

firebase.json for react-native-firebase v6:

{
  "react-native": {
    "crashlytics_disable_auto_disabler": true,
    "crashlytics_debug_enabled": true,
    "crashlytics_auto_collection_enabled": true,
    "perf_auto_collection_enabled": true,
    "analytics_auto_collection_enabled": true
  }
}

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: #### `AppDelegate.m`: ```objc - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.moduleRegistryAdapter = [[UMModuleRegistryAdapter alloc] initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc] init]]; RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"app" initialProperties:nil]; rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; rnBridgeFromRootView = rootView.bridge; //set the bridge to be exposed and returned later and used by the swift class self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [UIViewController new]; rootViewController.view = rootView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; // bootsplash [RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView]; // Firebase configuration // We get the Firebase config file name from the GoogleService-Info.plist // @see Replace GoogleService-Info.plist task [FIRApp configure]; [FIRMessaging messaging].delegate = self; [self initializeRemoteNotifications]; //.... return YES; } - (void) initializeRemoteNotifications { NSLog(@"[AppDelegate] Notifications - initializeRemoteNotification"); UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error) { if(!error) { [[UIApplication sharedApplication] registerForRemoteNotifications]; [RNNotifications startMonitorNotifications]; NSLog( @"[AppDelegate] Notifications - Push registration success." ); } else { NSLog( @"[AppDelegate] Notifications - Push registration FAILED" ); NSLog( @"[AppDelegate] Notifications - ERROR: %@ - %@", error.localizedFailureReason, error.localizedDescription ); NSLog( @"[AppDelegate] Notifications - SUGGESTIONS: %@ - %@", error.localizedRecoveryOptions, error.localizedRecoverySuggestion ); } } ]; } // This function is added here only for debugging purposes, and can be removed if swizzling is enabled. // If swizzling is disabled then this function must be implemented so that the APNs device token can be paired to // the FCM registration token. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSLog(@"[AppDelegate] Notifications - Register device token %@", deviceToken); // With swizzling disabled you must set the APNs device token here. [FIRMessaging messaging].APNSToken = deviceToken; // register to firebase for react-native-notifications library [RNNotifications didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { // The token is not currently available. NSLog(@"[AppDelegate] Notifications - Remote notification support is unavailable due to error: %@", err); // register to firebase for react-native-notifications library failed [RNNotifications didFailToRegisterForRemoteNotificationsWithError:err]; } //Called when a notification is delivered to a foreground app. -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { NSLog(@"[AppDelegate] Notifications - willPresentNotification"); completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge); } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo { NSLog(@"[AppDelegate] Notifications - didReceiveRemoteNotification"); [[FIRMessaging messaging] appDidReceiveMessage:userInfo]; [self application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:^(UIBackgroundFetchResult result) { NSLog(@"[AppDelegate] Notifications - didReceiveRemoteNotification (fetchCompletionHandler - UIBackgroundFetchResult)"); }]; } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{ NSLog(@"[AppDelegate] Notifications - didReceiveRemoteNotification (fetchCompletionHandler)"); completionHandler(UIBackgroundFetchResultNewData); } ```


mikehardy commented 4 years ago

You received a crash, what is the crash trace?

Aurelienlajoinie commented 4 years ago

Oh sorry, forgot to share it ...

Crash stack from crashlytics: image

From device log:

{"app_name":"app-iphone","timestamp":"2020-09-01 16:00:30.12 +0200","app_version":"3.17.1 - recette","slice_uuid":"20379eea-a080-3f9d-a3fc-bf423314d241","adam_id":0,"build_version":"502","bundleID":"fr.max.ios.recette","share_with_app_devs":false,"is_first_party":false,"bug_type":"109","os_version":"iPhone OS 13.3.1 (17D50)","incident_id":"4D37CFB0-5B6E-4D24-BD30-75B498C27C4D","name":"app-iphone"}
Incident Identifier: 4D37CFB0-5B6E-4D24-BD30-75B498C27C4D
CrashReporter Key:   dc14779b7d5fc5ff46a91d3b5dbd377a8b343930
Hardware Model:      iPhone10,6
Process:             app-iphone [1063]
Path:                /private/var/containers/Bundle/Application/DFA0C30F-8F2C-4CD0-94C6-F13033AB22C3/app-iphone.app/app-iphone
Identifier:          fr.test.app
Version:             502 (3.17.1 - recette)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           fr.test.app [1095]

Date/Time:           2020-09-01 16:00:29.7055 +0200
Launch Time:         2020-09-01 15:59:30.6270 +0200
OS Version:          iPhone OS 13.3.1 (17D50)
Release Type:        User
Baseband Version:    3.03.03
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGILL)
Exception Subtype: KERN_PROTECTION_FAILURE at 0x000000016ed4bfd0
VM Region Info: 0x16ed4bfd0 is in 0x16ed48000-0x16ed4c000;  bytes after start: 16336  bytes before end: 47
      REGION TYPE                      START - END             [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      mapped file            0000000133510000-00000001335d8000 [  800K] r--/r-- SM=SHM  ...t_id=f82bfa09
      GAP OF 0x3b770000 BYTES
--->  STACK GUARD            000000016ed48000-000000016ed4c000 [   16K] ---/rwx SM=NUL  ... for thread 0
      Stack                  000000016ed4c000-000000016ee48000 [ 1008K] rw-/rwx SM=COW  thread 0

Termination Signal: Illegal instruction: 4
Termination Reason: Namespace SIGNAL, Code 0x4
Terminating Process: app-iphone [1063]
Triggered by Thread:  0

Thread 0 name:  Dispatch queue: com.apple.usernotifications.UNUserNotificationServiceConnection
Thread 0 Crashed:
0   libsystem_malloc.dylib          0x00000001b4f5f118 0x1b4f5c000 + 12568
1   libsystem_malloc.dylib          0x00000001b4f5e5a4 0x1b4f5c000 + 9636
2   libsystem_malloc.dylib          0x00000001b4f5ea8c 0x1b4f5c000 + 10892
3   libsystem_malloc.dylib          0x00000001b4f6b928 0x1b4f5c000 + 63784
4   libsystem_malloc.dylib          0x00000001b4f6c20c 0x1b4f5c000 + 66060
5   libobjc.A.dylib                 0x00000001b4faf978 0x1b4f98000 + 96632
6   libdispatch.dylib               0x00000001b4f42a20 0x1b4ee7000 + 375328
mikehardy commented 4 years ago

Mmmm :thinking: that's probably not this module. Could be this module but my hunch is it probably is either code you are adding (what is that rich notification extension? What happens when you take it out? or it is upstream (try overriding to the 6.31.1 and doing npx react-native-clean-project to make sure it takes effect https://firebase.google.com/support/release-notes/ios (these overrides can be a point of bisection as well, perhaps going backwards in versions https://rnfirebase.io/#ios)

There is also


  [FIRMessaging messaging].delegate = self;

  [self initializeRemoteNotifications];

And tons of remote notifications code in AppDelegate. If you can reproduce with a clean example from https://github.com/mikehardy/rnfbdemo/blob/master/make-demo.sh and an App.js we can try to pinpoint it

Aurelienlajoinie commented 4 years ago

We are using several tools managing notifications, rich notification extension is a notification extension for one of them. This tools is used for remote and in app push campaign and the extension is necessary to manage notification with pictures/songs/video. We ara also using react-native-notification from wix in order to manage foreground and action on notifcations. And at the end a chat which is able receive notifications too... All AppDelegate code is here to satisfied those tools requirement.

I wiil try to override and upgrade SDK and let you know if it resolve our problem. Thanks for your help ;)

mikehardy commented 4 years ago

My hunch is the error is in all of the code you describe as necessary for various features - I'm not saying it is not necessary for your features, I'm just saying that if you temporarily rip it out (or, disable half of it if possible, to "bisect" the error by half iteratively) the problem is probably in there. Messaging is one of the most used features in this library and it is unlikely (possible! but unlikely) that there is a latent crash bug in the messaging code, especially when you have so much project-specific code in the area.

Aurelienlajoinie commented 4 years ago

Hello, updating to Native SDK v6.31.1 doesn't solve our problem. Now i will try to remove some AppDelegate specific code to find the real problem.

EDIT: I found the problem, but not the solution... when i remove our in-app/remote push campaign tool it works ! So the problem is between messaging and this one but this tool's code isn't open source. So i will wait for an update and if this new version fix the problem i will remove the patch-package on messaging.

stale[bot] commented 4 years ago

Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.