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

πŸ”₯[πŸ›] iOS - Cloud Messaging - No messageId on onMessage handler. Only receiving sender and data. #4362

Closed idjokic-spiria closed 3 years ago

idjokic-spiria commented 4 years ago

Issue

We're relying on messageId to deal with edge cases where we receive the same message multiple times. The process works well on Android, but not on iOS.

messageId is not being passed to our message handler for onMessage. Specifically, only sender and data are coming through. Per the docs, if this value is not passed, a random value should be generated.

Does messageId generation rely on something else? We do have a few settings missing while our client gets the details for us, such as App Store ID and Push Notification keys, etc.


Project Files

Javascript

Click To Expand

#### `package.json`: ```json "dependencies": { "@react-native-firebase/app": "^7.0.1", "@react-native-firebase/iid": "^7.0.1", "@react-native-firebase/messaging": "^7.0.1", "react-native": "0.63.2", ... ``` #### `firebase.json` for react-native-firebase v6: ```json { "react-native": { "messaging_android_notification_color": "@color/gray" } } ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' require_relative '../node_modules/react-native/scripts/react_native_pods' require_relative '../node_modules/react-native-unimodules/cocoapods.rb' platform :ios, '10.0' target 'universalApp' do use_unimodules! rn_maps_path = '../node_modules/react-native-maps' pod 'react-native-google-maps', :path => rn_maps_path pod 'GoogleMaps' pod 'Google-Maps-iOS-Utils' config = use_native_modules! use_react_native!(:path => config["reactNativePath"]) target 'universalAppTests' do inherit! :complete # Pods for testing end # Enables Flipper. # # Note that if you have use_frameworks! enabled, Flipper will not work and # you should disable these next few lines. use_flipper! post_install do |installer| flipper_post_install(installer) end end target 'universalApp-tvOS' do # Pods for universalApp-tvOS target 'universalApp-tvOSTests' do inherit! :search_paths # Pods for testing end end ``` #### `AppDelegate.m`: ```objc #import "AppDelegate.h" #import #import #import #import #import #import #import #import #import #ifdef FB_SONARKIT_ENABLED #import #import #import #import #import #import static void InitializeFlipper(UIApplication *application) { FlipperClient *client = [FlipperClient sharedClient]; SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]]; [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; [client addPlugin:[FlipperKitReactPlugin new]]; [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; [client start]; } #endif @interface AppDelegate () @property (nonatomic, strong) UMModuleRegistryAdapter *moduleRegistryAdapter; @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { #ifdef FB_SONARKIT_ENABLED InitializeFlipper(application); #endif [GMSServices provideAPIKey:@"AIzaSyCn5xxW7H32cohHJOMkOZrH3u0r0beqS_I"]; // add this line using the api key obtained from Google Console if ([FIRApp defaultApp] == nil) { [FIRApp configure]; } self.moduleRegistryAdapter = [[UMModuleRegistryAdapter alloc] initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc] init]]; RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"universalApp" initialProperties:nil]; rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [UIViewController new]; rootViewController.view = rootView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; // [REQUIRED] Register BackgroundFetch [[TSBackgroundFetch sharedInstance] didFinishLaunching]; return YES; } - (NSArray> *)extraModulesForBridge:(RCTBridge *)bridge { NSArray> *extraModules = [_moduleRegistryAdapter extraModulesForBridge:bridge]; // If you'd like to export some custom RCTBridgeModules that are not Expo modules, add them here! return extraModules; } - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; #else return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; #endif } @end ```


Environment

Click To Expand

**`react-native info` output:** ``` System: OS: macOS 10.15.5 CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz Memory: 27.19 MB / 16.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node Yarn: 1.21.1 - /usr/local/bin/yarn npm: 6.9.2 - ~/.nvm/versions/node/v10.15.3/bin/npm Watchman: Not Found Managers: CocoaPods: 1.9.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.0, DriverKit 19.0, macOS 10.15, tvOS 14.0, watchOS 7.0 Android SDK: API Levels: 23, 28, 29 Build Tools: 23.0.1, 28.0.3, 29.0.0, 29.0.2 System Images: android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-29 | Google APIs Intel x86 Atom Android NDK: Not Found IDEs: Android Studio: 4.0 AI-193.6911.18.40.6514223 Xcode: 12.0.1/12A7300 - /usr/bin/xcodebuild Languages: Java: 1.8.0_242 - /usr/bin/javac Python: 3.8.0 - /Users/idjokic/.pyenv/shims/python npmPackages: @react-native-community/cli: Not Found react: 16.13.1 => 16.13.1 react-native: 0.63.2 => 0.63.2 react-native-macos: Not Found npmGlobalPackages: *react-native*: Not Found ``` - **Platform that you're experiencing the issue on**: - [x] iOS - [ ] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - @react-native-firebase/app@7.2.1 - @react-native-firebase/messaging@7.1.6 - **`Firebase` module(s) you're using that has the issue:** - Messaging - **Are you using `TypeScript`?** - `Y` & `typescript@3.9.5`


mikehardy commented 4 years ago

Hi there! Please upgrade to latest stable versions and re-test to confirm this still happens

idjokic-spiria commented 4 years ago

Will do, thank you. I've tried searching for closed issues surrounding this and hadn't seen anything.

idjokic-spiria commented 4 years ago

Alas, upgrading to the latest version seems to make the entire process fall apart, preventing any Firebase messages from being received. I've gone through the setup process to double check everything and it's as it should be.

I'll continue to investigate on my end.

idjokic-spiria commented 4 years ago

Using later versions still results in the message handler never being called, in my case at least. For the version that we are on, I've noticed that that iOS implementation will use the message_id value from data to form the messageId, otherwise it comes out undefined.

I'm still debugging why the later versions don't work for us.

mikehardy commented 4 years ago

@idjokic-spiria non-delivery may be related to this #4299 which has the obvious workaround of opening the app a second time but also has a workaround I just published where after upgrading to firebase-ios-sdk 6.34.0 and adding one extra line (to get the patch on FirebaseInstanceID) in your Podfile, it should work again

Sorry current versions are giving you trouble - it's not so much that there may be closed issues here but that issues like this are typically upstream, and if you use an old version of react-native-firebase it usually depends on an old version of underlying firebase-ios-sdk - they fix mountains of bugs there every release. So moving to just-released 6.34.0 (or even the Invertase patched branch I mention in #4299) is the best way to make sure we're not chasing something either already fixed or with possible solutions that are deprecated dead-ends

idjokic-spiria commented 4 years ago

Hey Mike! I'm testing on Simulator, but I've seen that thread and have tried closing / re-opening and no dice. My next step was actually to go try out your patched version.

Yeah that all makes sense. I really appreciate your help, I'll be sure to post my findings here as I test your branch.

Cheers.

mikehardy commented 4 years ago

Do not test messaging on a simulator, that's a hard rule I thought. The results will not be representative, and some of that has to do with the contents of the messages, they are in unexpected places on the simulator - there is an old issue here about that (don't have the link sorry) where someone discovered the actual JSON in the handler came out different in simulator vs device

messaging tests must be on a real device

idjokic-spiria commented 4 years ago

:| I feel this needs to be in capital letters in the documentation somewhere. Unless I've missed existing capital letters that say so already. Have I?

Thank you, I'll test my efforts on a real device. Simulator was just very convenient and allowed better debugging.

Cheers, Ivan.

mikehardy commented 4 years ago

https://rnfirebase.io/messaging/usage#receiving-messages first sentence?

idjokic-spiria commented 4 years ago

Gotcha, thank you. I had clearly missed that, as it had worked as desired with Android, and almost as desired with iOS simulators. Will proceed with testing.

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 3 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.