react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

Notification iOS with image not showing with FCM

Open idir-s opened this issue 7 years ago β€’ 49 comments

Issue

I want to receive notification with an image from FCM but the image is not display in the notification banner on iOS but work on Android.


Project Files

iOS

Click To Expand

ios/Podfile:

  • [ ] I'm not using Pods
  • [x] I'm using Pods and my Podfile looks like:
    pod 'Firebase/Core', '~> 6.3.0'
    pod 'GoogleIDFASupport', '~> 3.14.0'
    pod 'Firebase/Messaging', '~> 6.3.0'
    pod 'RNFirebase', :path => '../node_modules/react-native-firebase/ios'

AppDelegate.m:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
  [[RNFirebaseNotifications instance] didReceiveLocalNotification:notification];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
  [[RNFirebaseNotifications instance] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
  [[RNFirebaseMessaging instance] didRegisterUserNotificationSettings:notificationSettings];
}


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:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->


Environment

Click To Expand

react-native info output:

react-native : 0.60.4
  • Platform that you're experiencing the issue on:
    • [ ] iOS
  • **react-native-firebase
    • 5.5.6


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]

idir-s avatar Aug 01 '19 09:08 idir-s

I'm also having this problem. After attaching an image to a notification in Firebase, I would have expected the puppy to show up in the notification, but there's only text. Are there any extra steps or iOS code that has to be added to enable this functionality?

Screenshot 2019-08-04 17 48 43

booboothefool avatar Aug 04 '19 21:08 booboothefool

This should be something handled automatically by the device. I guess, it would be an SDK version update?

Ehesp avatar Aug 05 '19 07:08 Ehesp

I can see this was implemented back in April for Android but I can't find something similar on iOS

LuisRodriguezLD avatar Aug 10 '19 03:08 LuisRodriguezLD

Apparently we need to create an extension -> docs here.

Would be great if react-native-firebase could do this automatically :)

LuisRodriguezLD avatar Aug 10 '19 03:08 LuisRodriguezLD

@LuisRodriguezLD Were you able to get that notification service extension set up properly? If so, could you provide some steps?

booboothefool avatar Aug 11 '19 01:08 booboothefool

Yes! I made it work :) Here is what I did:

  1. Create a new Notification Service Extension In Xcode, File -> New -> Target -> Notification Service Extension Name it and save it ( I used NotificationServiceExtension but you can use whatever )

  2. This new target will need the pods as well, so in your pod file add

target 'NotificationServiceExtension' do
    pod 'Firebase/Messaging', '~> 6.3.0'
end

(Don't forget to pod install)

  1. Edit your NotificationService.m file in the NotificationServiceExtension folder, this was created automatically in step 1.

Import RNFirebaseMessaging at the top

#import "RNFirebaseMessaging.h"

And replace

self.contentHandler(self.bestAttemptContent);

with

[[FIRMessaging extensionHelper] populateNotificationContent:self.bestAttemptContent withContentHandler:contentHandler];

This video can get you started in step 1. This page has instructions on step 3.

If you get stuck let me know. Please note, step 1 automatically adds a deployment target version. Adjust according to your needs.

LuisRodriguezLD avatar Aug 11 '19 03:08 LuisRodriguezLD

I am running into some problems.

Screenshot 2019-08-11 00 25 54

react: 16.3.1
react-native: https://github.com/expo/react-native/archive/sdk-30.0.0.tar.gz
react-native-firebase: ~5.4.0

pod 'RNFirebase', :path => '../node_modules/react-native-firebase/ios'
pod 'Firebase/Core', '~> 5.4.0'
pod 'Firebase/Auth', '~> 5.4.0'
pod 'Firebase/Messaging', '~> 5.4.0'
pod 'Firebase/Storage', '~> 5.4.0'
pod 'Firebase/DynamicLinks', '~> 5.4.0'

Ugh I'm stuck on 5.4.0 and this might have to do with it? https://github.com/firebase/firebase-ios-sdk/pull/1503

booboothefool avatar Aug 11 '19 04:08 booboothefool

Yeah. I highly recommend you upgrade react-native-firebase to 5.5.6 which has the firebase sdk in 6.3.0

LuisRodriguezLD avatar Aug 11 '19 11:08 LuisRodriguezLD

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] avatar Sep 08 '19 12:09 stale[bot]

@LuisRodriguezLD thanks for your solution but I still get some glitch here. When app in background or foreground, my notification display perfectly with image. But when app is open image dose not show. Do you have any solution for that? Thanks for your support

ThanhQuang1410 avatar Sep 11 '19 04:09 ThanhQuang1410

@ThanhQuang1410 Sorry, I do not have a current solution for when the app is open. I am pretty sure it's a very similar approach.

I'll try to get an example running today but no promises. Feel free to DM me.

LuisRodriguezLD avatar Sep 16 '19 14:09 LuisRodriguezLD

@LuisRodriguezLD Awesome. Did you get a chance to try? I am facing a similar issue on Android as well. When the App is open expandable Notifications don't come, even if it's text. The Notification is received but it's not expandable.

sakinaboriwala avatar Sep 18 '19 06:09 sakinaboriwala

@LuisRodriguezLD Awesome. Did you get a chance to try? I am facing a similar issue on Android as well. When the App is open expandable Notifications don't come, even if it's text. The Notification is received but it's not expandable.

In android handle it by doing notification.android.setLargeIcon(IMAGE_URL); and pass image url as data

joshcho96 avatar Sep 18 '19 17:09 joshcho96

Yes! I made it work :) Here is what I did:

  1. Create a new Notification Service Extension In Xcode, File -> New -> Target -> Notification Service Extension Name it and save it ( I used NotificationServiceExtension but you can use whatever )
  2. This new target will need the pods as well, so in your pod file add
target 'NotificationServiceExtension' do
    pod 'Firebase/Messaging', '~> 6.3.0'
end

(Don't forget to pod install)

  1. Edit your NotificationService.m file in the NotificationServiceExtension folder, this was created automatically in step 1.

Import RNFirebaseMessaging at the top

#import "RNFirebaseMessaging.h"

And replace

self.contentHandler(self.bestAttemptContent);

with

[[FIRMessaging extensionHelper] populateNotificationContent:self.bestAttemptContent withContentHandler:contentHandler];

This video can get you started in step 1. This page has instructions on step 3.

If you get stuck let me know. Please note, step 1 automatically adds a deployment target version. Adjust according to your needs.

Π‘an you show an example of your code? When i try to add #import "RNFirebaseMessaging.h" i have error "file not found". Π ow did you modify the AppDelegate.m and AppDelegate.h files?

I use Firebase/Messaging', '~> 6.3.0' and react native 0.59.9

NikitaPFE avatar Sep 19 '19 12:09 NikitaPFE

@NikitaPFE there is not actual code besides that, it's just configuration.

file not found could be because you did not install the pods. did you follow step 2? Don't forget you need to pod install

LuisRodriguezLD avatar Sep 19 '19 15:09 LuisRodriguezLD

@LuisRodriguezLD Yes, I did pod install

You do not know whether to remove these methods from the AppDelegate.m?

Screen Shot 2019-09-19 at 19 50 54

NikitaPFE avatar Sep 19 '19 16:09 NikitaPFE

@NikitaPFE There is no need to remove that code from Appdelegate.m

To resolve file not found error, follow these steps:

Go to NotificationService Target -> Build Settings -> Search Header paths and add ->

$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase/messaging

Refer https://github.com/invertase/react-native-firebase/issues/632#issuecomment-359673796 for the same.

sakinaboriwala avatar Sep 19 '19 17:09 sakinaboriwala

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] avatar Oct 17 '19 17:10 stale[bot]

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.

stale[bot] avatar Nov 01 '19 17:11 stale[bot]

I'm also having this problem. After attaching an image to a notification in Firebase, I would have expected the puppy to show up in the notification, but there's only text. Are there any extra steps or iOS code that has to be added to enable this functionality?

Screenshot 2019-08-04 17 48 43

any solution you got for this ?

Dhavalmaheta avatar Nov 07 '19 13:11 Dhavalmaheta