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

iOS Background Notification troubleshooting #3367

Closed aslanon closed 3 years ago

aslanon commented 4 years ago

Issue

Hello, notifications run while the app is on the foregound, but I didn't receive any messages when the app is in the background or killed.

There are a lot of documentation but I can't solve this problem. What am I doing wrong?


Project Files

Javascript

Click To Expand

#### `package.json`: ```json "dependencies": { "@react-native-community/push-notification-ios": "^1.1.0", "@react-native-firebase/app": "^6.4.0-rc4", "@react-native-firebase/messaging": "^6.4.0-rc4", "react": "16.9.0", "react-native": "0.61.5", "react-native-push-notification": "^3.1.9", } ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby platform :ios, '10.0' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' target 'Myapp' do # Pods for Myapp 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 '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' pod 'react-native-orientation', :path => '../node_modules/react-native-orientation' target 'MyappTests' do inherit! :search_paths # Pods for testing end use_native_modules! end target 'Myapp-tvOS' do # Pods for Myapp-tvOS target 'Myapp-tvOSTests' do inherit! :search_paths # Pods for testing end end ``` #### `AppDelegate.m`: ```objc /** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #import "AppDelegate.h" #import #import #import #import #import #import #import "Orientation.h" @implementation AppDelegate // Required to register for notifications - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { [RNCPushNotificationIOS didRegisterUserNotificationSettings:notificationSettings]; } // Required for the register event. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } // Required for the notification event. You must call the completion handler after handling the remote notification. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; } // Required for the registrationError event. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error]; } // Required for the localNotification event. - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { [RNCPushNotificationIOS didReceiveLocalNotification:notification]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"Myapp" 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]; [FIRApp configure]; UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; return YES; } - (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:** ``` info Fetching system and libraries information... System: OS: macOS 10.15.1 CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz Memory: 2.36 GB / 16.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 12.13.0 - /usr/local/bin/node Yarn: 1.19.1 - /usr/local/bin/yarn npm: 6.12.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1 IDEs: Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild npmPackages: react: 16.9.0 => 16.9.0 react-native: 0.61.5 => 0.61.5 npmGlobalPackages: react-native-cli: 2.0.1 ``` - **Platform that you're experiencing the issue on**: - [x ] iOS - [ ] Android - [ x] **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:** - `none // because I removed when I use to 6.4.0-rc4` - **`Firebase` module(s) you're using that has the issue:** - `e.g. Instance ID` - **Are you using `TypeScript`?** - `N`


Think react-native-firebase is great? Please consider supporting all of the project maintainers and contributors by donating via our Open Collective where all contributors can submit expenses. [Learn More]

Salakar commented 4 years ago

For those with delegate issues when using other libraries please try 6.4.1-alpha.0 from NPM - this should fix the issues - PR: #3427

mori5321 commented 4 years ago

@Salakar I confirmed that Foreground Messaging properly worked on '6.4.1-alpha.0' !!!! ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰ And Background Messaging also has no problem. I appreciate you fixing this bug. Thank you. @Salakar

Here's my environment.

Envs

Device: iPhone11 iOS 13.3.1 npm Libraries:

Output by console.log

Image from Gyazo

My Sample Code

My Code is like this.

const SampleScreen = (props) => {
  const setForegroundMessageHandler = () => {
    const unsubscriber = messaging().onMessage(remoteMessage => {
      console.log(JSON.stringify(remoteMessage));
    })
    return unsubscriber
  }

  useEffect(() => {
    const unsubscriber = setForegroundMessageHandler();

    return () => {
      unsubscriber()
    }
  }, [])
}

Thank you so much !!!!!! ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰

bsonmez commented 4 years ago
"@react-native-firebase/app": "6.4.1-alpha.0",
"@react-native-firebase/iid": "6.4.1-alpha.0",
"@react-native-firebase/messaging": "6.4.1-alpha.0",

The new alpha release looks like solved the issue so far.

LuongTruong commented 4 years ago

Hello @Salakar , thank you for the new version it solved the delegate issue

radko93 commented 4 years ago

@mori5321 @bsonmez @LuongTruong are you able to display local notification when in foreground?

LuongTruong commented 4 years ago

@radko93 , I have to use another lib like: react-native-push-notification to display the local notification. Currently, react-native-firebase doesn't support this, you can take a look at this link

With the new version 6.4.1-alpha.0, I am able to make the react-native-push-notification work with react-native-firebase.

Hope this comment can help you ๐Ÿ˜„

embpdaniel commented 4 years ago

I was previously not able to display local notifications with react-native-push-notification and react-native-firebase version 6.4.0-rc4. This new version 6.4.1-alpha.0 fixed this for me. Thank you!

bsonmez commented 4 years ago

@mori5321 @bsonmez @LuongTruong are you able to display local notification when in foreground?

For notifications, you should use another lib like @LuongTruong mentioned.

radko93 commented 4 years ago

@bsonmez that's what I'm using. I have to recheck.

mstfymrtc commented 4 years ago

Did you apply these requirements for iOS @aslanon? Even if you add "Background Modes (Background fetch+Remote notifications) and Push Notifications" as capabilities in XCode, also you have to add them here if you don't allow Xcode to "Automatically manage signing." Then you have to regenerate Provision Profile as described in here from here.

Applying all of these by following rnfirebase docs, works on me with:

"@react-native-firebase/app": "^6.4.0", "@react-native-firebase/messaging": "^6.4.0", "react-native": "0.61.5"

Ehesp commented 4 years ago

Thanks @mstfymrtc - the entire Apple process for setting up APNs to work with FCM is horrible. It's best to triple check your XCode/Apple account to ensure everything is matched up.

dsomel21 commented 4 years ago

@LuongTruong I've seen that documentation too, but I was still left with some open questions.

Screen Shot 2020-04-16 at 6 02 48 PM

The reason this chart doesn't make sense is because, when my App is in the background or is killed I can still still receive Push notifications from my server.

The problem is listening to events that I can't seem to find a definitive answer for in any documentation or any thread. So I am going to ask it here, hopefully someone can shed some light. Is it possible in iOS to have push notification event listeners for incoming notifications that work even when the React Native app is killed/not running?

Just for more context, my Ruby server can fire a push notification on scheduled dates.

response = HTTParty.post("https://fcm.googleapis.com/fcm/send",
  body: {
    "notification": {
      "title": "Test 3000",
      "body": "This is a test",
      "sound", "default"
    }
  },
  headers: {
    "Content-Type" => "application/json",
    "Authorization" => "key=#{api_key}"
  }
)

And then be able to listen:

messaging().setBackgroundMessageHandler(async remoteMessage => {
  // update the icon badge
});
dsomel21 commented 4 years ago

I found link on someones Medium blog, when she was talking about the lack of support for sending remote silent notifications.

Basically, Apple SDK (or whatever, I am not an iOS Developer) has a method called: didReceiveRemoteNotification

the system launches your app (or wakes it from the suspended state) and puts it in the background state when a remote notification arrives. However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.

Here is the Apple thread:

https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623013-application

alessandrofc commented 4 years ago

For me, background messages still not working even using 6.4.1-alpha.0. Foreground messages works properly.

ASchwad commented 4 years ago

For me, notifications are working properly now for iOS in fore- and background with the new version.

@alessandrofc did you already try the backgroundMessageHandler? https://rnfirebase.io/messaging/usage#background--quit-state-messages

Ehesp commented 4 years ago

The reason this chart doesn't make sense is because, when my App is in the background or is killed I can still still receive Push notifications from my server.

A message & notification are different things. A message is just a payload of data, a notification is what is physically shown on the device.

Is it possible in iOS to have push notification event listeners for incoming notifications that work even when the React Native app is killed/not running?

Yes, the code you posted below should be working fine (setBackgroundMessageHandler)?

alessandrofc commented 4 years ago

@ASchwad yes. Here is my index.js

Envs Device: iPhone5s iOS 12.4.5 npm Libraries:

"@react-native-firebase/app": "6.4.1-alpha.0", "@react-native-firebase/messaging": "6.4.1-alpha.0", "react-native": "~0.61.5", "react": "~16.9.0",

` import messaging from '@react-native-firebase/messaging'; import React from 'react'; import { AppRegistry } from 'react-native'; import App from './App'; import { name as appName } from './app.json';

messaging().setBackgroundMessageHandler(async remoteMessage => { console.warn('setBackgroundMessageHandler', JSON.stringify(remoteMessage)); });

function HeadlessCheck({ isHeadless }) { console.log('isHeadless', isHeadless);

if (isHeadless) {
    return null;
}

return <App />;

}

AppRegistry.registerComponent(appName, () => HeadlessCheck); `

nobodyabcd commented 4 years ago

Have anyone encounter this scenario ===> On IOS real device and receive FCM in background state.

For me, I was able to receive the message on background but no sounds was played even though I set sound equal to true.

dreson4 commented 4 years ago

Tried everything on this thread nothing works. I can still receive foreground messages but background messages don't work.

And those with edited AppDeligate.m file I didnโ€™t see any where in the documentation with that information.

Ehesp commented 4 years ago

@dreson4 something isn't setup correctly then. Try looking at the native logs to see whats going wrong.

Also, Foreground message use a websocket connection directly to FCM and bypass APNs, so there is something up with that side.

dreson4 commented 4 years ago

@Ehesp I have seen people on this thread with imports like

#import <RNCPushNotificationIOS.h>
#import <UserNotifications/UserNotifications.h>

Do I need to import those as well? And add the extra code? I havenโ€™t seen anywhere in the documentation with a mention of this. I only have firebase imported. And Iโ€™m using 6.4.1-alpha.0

Ehesp commented 4 years ago

Nope, shouldn't need to. Try using 6.4.1-alpha.0

dreson4 commented 4 years ago

Ok, for some reason without changing anything. It works now after restarting Xcode and just building the app again.

alessandrofc commented 4 years ago

For me still not working. I even created a new project and set it up again and the problem persists. Only foreground messages are working.

nobodyabcd commented 4 years ago

For me still not working. I even created a new project and set it up again and the problem persists. Only foreground messages are working.

Maybe you should share your code here and show us how to deal with background message. So we can look at it together

aslanon commented 4 years ago

Solved. ๐ŸŽ‰

The problem is solved with help of @ahmet. When the FirebaseAppDelegateProxyEnabled value is YES, background notification is running.

Also thanks to @andreasanta.

As far as I know, as long as you set FirebaseAppDelegateProxyEnabled=YES in your Info.plist - or leave it unset - the native module delegates should be called transparently. So no need to alter your AppDelegate.m.

alessandrofc commented 4 years ago

I created a test project. If someone could help find the problem, I'll appreciate.

https://github.com/alessandrofc/rnfirebasepush

nobodyabcd commented 4 years ago

I created a test project. If someone could help find the problem, I'll appreciate.

  • I only removed my GoogleService-Info.plist file.

https://github.com/alessandrofc/rnfirebasepush

You know what, you should update your package.json from:

(You project used 6.4.0, which is not right)

    "@react-native-firebase/app": "^6.4.0",
    "@react-native-firebase/messaging": "^6.4.0",

to:

    "@react-native-firebase/app": "6.4.1.alpha0",
    "@react-native-firebase/messaging": "6.4.1.alpha0",
alessandrofc commented 4 years ago

@guanhuay Yes, I tried this version previously, but no success.

bsonmez commented 4 years ago

@guanhuay Yes, I tried this version previously, but no success.

Did you install pod again after you upgraded the package?

Update your package.json as follows:

 "@react-native-firebase/app": "6.4.1.alpha0",
 "@react-native-firebase/messaging": "6.4.1.alpha0",

Then : cd ios && pod install

alessandrofc commented 4 years ago

@bsonmez Yes.

robertqin86 commented 4 years ago

Solved. ๐ŸŽ‰

The problem is solved with help of @ahmet. When the FirebaseAppDelegateProxyEnabled value is YES, background notification is running.

Also thanks to @andreasanta.

As far as I know, as long as you set FirebaseAppDelegateProxyEnabled=YES in your Info.plist - or leave it unset - the native module delegates should be called transparently. So no need to alter your AppDelegate.m.

It's still not solved for me. FirebaseAppDelegateProxyEnabled: YES is actually not needed as the default value for appDelegateSwizzled is YES.

rppires commented 4 years ago

I was also having trouble with background notifications.

It took me a while to understand, but the background notification is only triggered when there is "notification" in the payload. it should be obvious, but the example I was using was wrong.

Authorization=key=[server_key] Content-Type:application/json post: https://fcm.googleapis.com/fcm/send

{
    "data": {
        "notification": {
            ...
        }
    }
    to: "device_Id"
}

The correct thing is like this:

{
    "notification": {
        "body": "...",
        "title": "...",
        "sound": true,
        "priority": "high"
    },
   to: "device_Id"
}

Only then when I put it in the correct format I managed to catch the error, in which case the error was: "InvalidApnsCredential"

Understand, even with this error I was able to trigger the foreground notification.

The solution was found here on Oliver's comment : https://stackoverflow.com/questions/43515467/firebase-invalidapnscredential-while-certificates-are-valid#_=_

Reupload the key with is format AuthKey_{TEAM_ID}.p8


I don't know if this information will contribute to anything, but it solved

programmer-RN commented 4 years ago

For me, background messages still not working even using 6.4.1-alpha.0. Foreground messages works properly.

Hi, I'm failed in foreground message in iOS. May I know how you do it?

Ehesp commented 4 years ago

@programmer-RN stop spamming issues with single line comments.

remigallego commented 4 years ago

I've got the same problem on iPhone 11 - 13.3.1. Push + Remote Notifications capabilities enabled.

Remote notifications work OK when the app is active, but nothing is displayed when I put the app in background and try to send notifications either from the Firebase console or via Postman.

Tried 6.4.1-alpha.0 and FirebaseAppDelegateProxyEnabled without success.

bockc commented 4 years ago

@remigallego I managed to get notifications to work in foreground and background states, but my backgroundMessageHandler does not fire when the app is in quit state on iOS, I don't understand why. I receive the notification and it's displayed, but I need the code in my handler to be called

mikehardy commented 4 years ago

If you look at the upstream SDK references, of the 3 states in iOS, if the application was actually killed by the user (I think what you mean by quit state), it's just dead until phone restarts or user starts the app again.

bockc commented 4 years ago

@mikehardy So you mean if a user on iOS swipes up the application from the app switcher, you won't be able to wake it up and trigger the background helper ? I thought that there was a difference between "force quit" and "quit"

nobodyabcd commented 4 years ago

@remigallego I managed to get notifications to work in foreground and background states, but my backgroundMessageHandler does not fire when the app is in quit state on iOS, I don't understand why. I receive the notification and it's displayed, but I need the code in my handler to be called

Hi there, I have similar issue before, but I resolved it by define my FCM payload (cloud functions side) like below and now i was able to receive FCM from background or quit state, please give this a try:

const message = {
  topic: topicName,
  notification: {
    title: `title`,
    body: "body"
  },
  android: {
    priority: "high"
  },
  apns: {
    payload: {
      aps: {
        sound: "default",
        "content-available": 10
      }
    }
  }
};
mikehardy commented 4 years ago

@bockc that is what I meant. If the user swipes your app away is generally called "force close" and iOS takes it as an affirmative signal that your app should stop doing anything and behaves accordingly, that's my understanding

@guanhuay the problem with your scenario is that you are sending a UI notification that way - it will deliver the notification to the phone and show it to the user but I don't believe the app gets control, and then you need to handle local device notification APIs in order to handle the click, which is then not part of react-native-firebase, it's not a cloud message action at that point, it's a local notification click. There's no way to do it with a data-only cloud message a.k.a. "silent push"

remigallego commented 4 years ago

@remigallego I managed to get notifications to work in foreground and background states, but my backgroundMessageHandler does not fire when the app is in quit state on iOS, I don't understand why. I receive the notification and it's displayed, but I need the code in my handler to be called

Hi there, I have similar issue before, but I resolved it by define my FCM payload (cloud functions side) like below and now i was able to receive FCM from background or quit state, please give this a try:

const message = {
  topic: topicName,
  notification: {
    title: `title`,
    body: "body"
  },
  android: {
    priority: "high"
  },
  apns: {
    payload: {
      aps: {
        sound: "default",
        "content-available": 10
      }
    }
  }
};

I still do not get UI notification on the iPhone this way. :(

nobodyabcd commented 4 years ago

@remigallego I managed to get notifications to work in foreground and background states, but my backgroundMessageHandler does not fire when the app is in quit state on iOS, I don't understand why. I receive the notification and it's displayed, but I need the code in my handler to be called

Hi there, I have similar issue before, but I resolved it by define my FCM payload (cloud functions side) like below and now i was able to receive FCM from background or quit state, please give this a try:

const message = {
  topic: topicName,
  notification: {
    title: `title`,
    body: "body"
  },
  android: {
    priority: "high"
  },
  apns: {
    payload: {
      aps: {
        sound: "default",
        "content-available": 10
      }
    }
  }
};

I still do not get UI notification on the iPhone this way. :(

have you add apn push key to ur firebase project?

JWW87 commented 4 years ago

@bockc that is what I meant. If the user swipes your app away is generally called "force close" and iOS takes it as an affirmative signal that your app should stop doing anything and behaves accordingly, that's my understanding

@guanhuay the problem with your scenario is that you are sending a UI notification that way - it will deliver the notification to the phone and show it to the user but I don't believe the app gets control, and then you need to handle local device notification APIs in order to handle the click, which is then not part of react-native-firebase, it's not a cloud message action at that point, it's a local notification click. There's no way to do it with a data-only cloud message a.k.a. "silent push"

I am also experiencing this behaviour on iOS. On Android the data only messages work fine (foreground, background and quit). On iOS it works only when the app is in the foreground of background. When the app is swiped up (force quit / killed) it doesn't respond to a data only message. I can confirm the message is received, because I hear a sound when I add sound: "default" to the message.

I think it should be possible that an iOS app is started on a data only message so setBackgroundMessageHandlercan be called. You can for instance force quit WhatsApp and you will still receive messages with local notifications. Does anyone have any idea how to get this working?

PS: I know you can add notification to a data message. The notification will indeed show up even in quit state. However like mikehardy said, you can't add any kind of payload to that notification, which is really necessary most of the time.

mikehardy commented 4 years ago

Right, everyone thinks it should be possible to wake their app up and have it do whatever the developer wants. But Apple iOS does not support that, so it is not possible. Your best bet is to do something like react-native-background-fetch in an attempt to have your app wake up periodically. But that's also strongly governed by the iOS power AI and if the user doesn't use your app, you don't wake up

Welcome to mobile development? (kind of sincere but more just a not really funny joke, sorry)

aecorredor commented 4 years ago

Make sure you are requesting permissions correctly. That was the issue for me. When I migrated from v5 to v6 my hasPermission check broke because now it returns a number (-1, 0, or 1) instead of a boolean to signify the permission status.

bockc commented 4 years ago

@mikehardy Indeed, not really funny, especially because there actually may be new devs here, and many "native stuff" such as iOS resources limitations are not something you naturally stomp upon when doing react-native ;)

Anyway, if so many people seem to think that firebase allows them to do such a thing as waking up an iOS device when the app was "force quit", maybe it's not only because they're new to mobile development but because the firebase documentation is unclear on that subject. I may not be the best example, but I've been doing mobile development for a few years now and I am aware of iOS limitations on the device's resources, and still, after reading firebase's cloud messaging documentation a good few times thoroughly, I definitely thought that firebase found some kind of workaround to do it.

First, look at this part of the documentation: https://rnfirebase.io/messaging/usage#message-handlers This is incredibly misleading. In the array above you can see that if your app is in "quit state", firebase will call setBackgroundMessageHandler which according to you and my testings, seems totally impossible. Even the text paragraph below got me to think "Ok, if the backgroundHandler does not work with a notification, let's try with a data only message and find a way to display the notifications here" etc. I think there are some missing details in this part of the documentation.

Then, have a look here: https://rnfirebase.io/messaging/usage#notifications Once again, I see that if I receive a notification when my app is quit, my backgroundHandler will be called according to the array at the beginning (misleading, needs more details I guess)

Finally, the final blow to any doubts left in your mind: https://rnfirebase.io/messaging/usage#background--quit-state-messages This here. This whole part, from the very beginning of the very first phrase lets you think that INDEED YOU CAN CALL YOUR JS WHEN iOS IS CLOSED. It even tells it to you black on white straight away as you start reading : When the application is in a background or quit state [...], you need to setup a background callback handler via the setBackgroundMessageHandler method.

Also, here's the official Apple documentation for the didReceiveRemoteNotification method. https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623013-application At some point, you can read: However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again. So, okay, I get it, if you force-quit an app (let's say from the settings), you won't be able to wake up your app, seems fair to me. So, firebase is talking about "quit mode", which definitely sounds different from Apple's "force quit mode", so I guess swiping up from the app switcher on iOS quits the app, and if there's any issue you can force quit it from somewhere else.

Honestly, at this point I'm very confused because either:

So Mike, if you're telling me that it's indeed not possible to wake up a quit iOS app using firebase, I guess you know your subject better than me, so I will believe you. But please, tell the firebase team to improve their documentation a little bit to avoid this kind of misleading stuff/misinterpretation. As you can see in this issue, all over the internet and even in my team, we all got tricked by the way the documentation is presented/written.

mikehardy commented 4 years ago

No, it is not funny, it is painful. PRs to documentation are happily accepted

bsonmez commented 4 years ago

I think there is no stability. It was working without making any changes before. But it doesn't work since I deleted the app and installed it again. I couldn't understand the reason.

After I deleted node_modules and Pods and reinstall to see if there will be any changes. However, it also didn't work as well.

Package.json

"@react-native-firebase/app": "6.7.1",
"@react-native-firebase/messaging": "6.7.1",
"react-native": "0.61.5",

Device iPhone 7 Plus iOS 13.4.1

mikehardy commented 4 years ago

@bsonmez deleted the app and reinstalled again, what could change? The token I think. You may be addressing the old token.