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.7k stars 2.22k forks source link

[🐛] Default sound not working on iOS #6277

Closed astrahov closed 2 years ago

astrahov commented 2 years ago

Issue

Default sound not working on iOS.

  1. The code indicates that you can use banners, stickers and sounds.
  2. Request data in devices that will sound in the Republic...
  3. After confirmation in the implementation, it appeared that the sound was turned on.
  4. When testing the "Do not disturb" and "Focus" modes are turned off, the sound is turned on.

With other applications, PUSH comes, there is sound, in my application PUSH comes - there is no sound.

import messaging from '@react-native-firebase/messaging'

const TestComponent = () => {
    useEffect(() => {
        messaging()
            .requestPermission({
                alert: true, // <<-------
                announcement: false,
                badge: true, // <<-------
                carPlay: false,
                provisional: false,
                sound: true, // <<-------
            })
            .then(() => {
                // ...
            })
            .catch((error) => {
                // ...
            })
            .finally(() => {
                // ...
            })
    }, [])
}

Project Files

Javascript

Click To Expand

#### `package.json`: ```json { "dependencies": { "@react-native-firebase/app": "^14.10.0", "@react-native-firebase/messaging": "^14.10.0", "react": "17.0.2", "react-native": "0.68.2", }, } ``` #### `firebase.json` for react-native-firebase v6: ```json # N/A ```

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/scripts/react_native_pods' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' platform :ios, '11.0' install! 'cocoapods', :deterministic_uuids => false target 'SpecialistApp' do config = use_native_modules! # Flags change depending on the env values. flags = get_default_flags() use_react_native!( :path => config[:reactNativePath], # to enable hermes on iOS, change `false` to `true` and then install pods # npm package dependence: realm # :hermes_enabled => flags[:hermes_enabled], # hermes_enabled Default from React Native / Нельзя true из-за Realm (до внедрения поддержки) :hermes_enabled => false, :fabric_enabled => flags[:fabric_enabled], # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/.." ) # ---------------------------------------------------------------------------- # npm package dependence: react-native-permissions permissions_path = '../node_modules/react-native-permissions/ios' pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse" pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications" # ---------------------------------------------------------------------------- target 'SpecialistAppTests' 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 the next line. use_flipper!() post_install do |installer| react_native_post_install(installer) __apply_Xcode_12_5_M1_post_install_workaround(installer) end end ``` #### `AppDelegate.m`: ```objc #import "AppDelegate.h" #import #import #import #import // npm package dependence: @react-native-firebase #import #if RCT_NEW_ARCH_ENABLED #import #import #import #import #import #import #import @interface AppDelegate () { RCTTurboModuleManager *_turboModuleManager; RCTSurfacePresenterBridgeAdapter *_bridgeAdapter; std::shared_ptr _reactNativeConfig; facebook::react::ContextContainer::Shared _contextContainer; } @end #endif @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { RCTAppSetupPrepareApp(application); // npm package dependence: @react-native-firebase [FIRApp configure]; RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; #if RCT_NEW_ARCH_ENABLED _contextContainer = std::make_shared(); _reactNativeConfig = std::make_shared(); _contextContainer->insert("ReactNativeConfig", _reactNativeConfig); _bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer]; bridge.surfacePresenter = _bridgeAdapter.surfacePresenter; #endif UIView *rootView = RCTAppSetupDefaultRootView(bridge, @"SpecialistApp", nil); if (@available(iOS 13.0, *)) { rootView.backgroundColor = [UIColor systemBackgroundColor]; } else { rootView.backgroundColor = [UIColor whiteColor]; } self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [UIViewController new]; rootViewController.view = rootView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; return YES; } - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; #endif } #if RCT_NEW_ARCH_ENABLED #pragma mark - RCTCxxBridgeDelegate - (std::unique_ptr)jsExecutorFactoryForBridge:(RCTBridge *)bridge { _turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge delegate:self jsInvoker:bridge.jsCallInvoker]; return RCTAppSetupDefaultJsExecutorFactory(bridge, _turboModuleManager); } #pragma mark RCTTurboModuleManagerDelegate - (Class)getModuleClassFromName:(const char *)name { return RCTCoreModulesClassProvider(name); } - (std::shared_ptr)getTurboModule:(const std::string &)name jsInvoker:(std::shared_ptr)jsInvoker { return nullptr; } - (std::shared_ptr)getTurboModule:(const std::string &)name initParams: (const facebook::react::ObjCTurboModule::InitParams &)params { return nullptr; } - (id)getModuleInstanceFromClass:(Class)moduleClass { return RCTAppSetupDefaultModuleFromClass(moduleClass); } #endif @end ```


Android

Click To Expand

#### Have you converted to AndroidX? - [ ] my application is an AndroidX application? - [ ] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [ ] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy import org.apache.tools.ant.taskdefs.condition.Os // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { buildToolsVersion = "31.0.0" minSdkVersion = 21 compileSdkVersion = 31 targetSdkVersion = 31 if (System.properties['os.arch'] == "aarch64") { // For M1 Users we need to use the NDK 24 which added support for aarch64 ndkVersion = "24.0.8215888" } else { // Otherwise we default to the side-by-side NDK version from AGP. ndkVersion = "21.4.7075529" } } repositories { google() mavenCentral() } dependencies { classpath("com.android.tools.build:gradle:7.0.4") classpath("com.facebook.react:react-native-gradle-plugin") classpath("de.undercouch:gradle-download-task:4.1.2") // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files // npm package dependence: @react-native-firebase classpath("com.google.gms:google-services:4.3.10") } } allprojects { repositories { maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url("$rootDir/../node_modules/react-native/android") } maven { // Android JSC is installed from npm url("$rootDir/../node_modules/jsc-android/dist") } mavenCentral { // We don't want to fetch react-native from Maven Central as there are // older versions over there. content { excludeGroup "com.facebook.react" } } google() maven { url 'https://www.jitpack.io' } } } ``` #### `android/app/build.gradle`: ```groovy // npm package dependence: @react-native-firebase apply plugin: 'com.google.gms.google-services' dependencies { // ... // npm package dependence: @react-native-firebase implementation platform('com.google.firebase:firebase-bom:30.0.2') // ... } ``` #### `android/settings.gradle`: ```groovy rootProject.name = 'SpecialistApp' apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app' includeBuild('../node_modules/react-native-gradle-plugin') if (settings.hasProperty("newArchEnabled") && settings.newArchEnabled == "true") { include(":ReactAndroid") project(":ReactAndroid").projectDir = file('../node_modules/react-native/ReactAndroid') } ``` #### `MainApplication.java`: ```java // N/A ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` System: OS: macOS 12.3.1 CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz Memory: 153.71 MB / 8.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 17.0.1 - /usr/local/bin/node Yarn: Not Found npm: 8.3.0 - /usr/local/bin/npm Watchman: 2021.11.15.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5 Android SDK: Not Found IDEs: Android Studio: 2021.2 AI-212.5712.43.2112.8512546 Xcode: 13.4/13F17a - /usr/bin/xcodebuild Languages: Java: 11.0.15 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.68.2 => 0.68.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:** - `14.10.0` - **`Firebase` module(s) you're using that has the issue:** - `app, messaging` - **Are you using `TypeScript`?** - `N`

mikehardy commented 2 years ago

Hmm :thinking: Real device? What model? When plugged in to a developer machine and running app do you see anything in the console logs from firebase-ios-sdk or the system when the message is delivered? The system / SDK frequently log a few things about whether to deliver the message or not Contents of the JSON you send via FCM REST API to test? Confirm that your background handler was actually called / FCM was delivered, and it really is just the sound not playing? Do you have any configuration for the sound or is it just default sound? Screenshot of notification settings for the app with all the details to confirm that the app really does have all the required settings turned on?

Yes, this is mostly a fishing expedition - it is looking at anything and everything to see what could cause the issue. I haven't seen this myself (I don't use sounds for notifications) so I'm not the most familiar in the area, and no one else has reported it, so it's going to involve a lot of triage on your part to determine what's going on, and - to set expectations - I will most likely only be able to offer advice about where to look + ideas to troubleshoot as you determine the root cause in your environment through your efforts

astrahov commented 2 years ago

Device

Real device: iPhone 12, iOS 15.5

Test

Unfortunately, the text only happens through TestFlight, with no connection to the developer's machine.

I'm testing through the Firebase Console. I specify only the title and the message.

Delivery confirmation

My app / sound - no ((

IMG_6924

Telegram / sound - yes (For comparison)

IMG_6923

Default sound

I don't use custom sounds, only the default sound.

Settings

My app

IMG_6927 IMG_6928

Telegram (For comparison)

IMG_6925 IMG_6926

mikehardy commented 2 years ago

Unfortunately, the text only happens through TestFlight, with no connection to the developer's machine.

I am not sure how you plan on debugging it then?

I'm testing through the Firebase Console. I specify only the title and the message.

Then you are not strictly in control of the JSON sent, so it's also difficult to debug. It's pretty easy to write a little shell script that uses curl to post a JSON to the FCM REST API, once you have the device token. You should do that so you know exactly what JSON you are sending and can try different things

These questions are important, you'll need to get familiar with how to answer them in order to troubleshoot cloud messaging from any vendor:

When plugged in to a developer machine and running app do you see anything in the console logs from firebase-ios-sdk or the system when the message is delivered? The system / SDK frequently log a few things about whether to deliver the message or not Contents of the JSON you send via FCM REST API to test? Confirm that your background handler was actually called / FCM was delivered, and it really is just the sound not playing?

astrahov commented 2 years ago

I figured out the problem! It turned out to be a server problem, or rather a third-party library that the server uses to send PUSH.

This library: https://pypi.org/project/pyfcm/

The solution to the problem turned out to be to add a parameter: sound=True.

There is no information about it in their documentation :(