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

iOS Foreground notification not showing

Open sharavana06 opened this issue 9 years ago • 8 comments

Issue

Hi, Using below code to show notification in iOS when app running in foreground.Background notification working properly. In console I can see the payload prints when app running in foreground but no notification/ banner shown.

this.firebase.messaging().createLocalNotification({

           title: 'Test App',     
            body: msg,
            icon: 'ic_launcher',
            id: new Date().getTime()+"",
            click_action: "ACTION",
            action: "Action",
            screen: "Chat",
           content_available:true, 
           show_in_foreground:true,
            priority:"high",
            sound: 'default',
            opened_from_tray: false });

My Podfile:

 platform
 :ios, '9.0'
target 'TestApp' do
pod 'Firebase/Core'
pod 'RNFirebase', :path => '../node_modules/react-native-firebase'
pod 'Firebase/AdMob'
pod 'Firebase/Analytics'
pod 'Firebase/Auth'
pod 'Firebase/Crash'
pod 'Firebase/Database'
pod 'Firebase/DynamicLinks'
pod 'Firebase/Messaging'
pod 'Firebase/RemoteConfig'
pod 'Firebase/Storage'
pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
pod 'React', :path => '../node_modules/react-native', :subspecs => [
'BatchedBridge','Core']
pod 'GoogleMaps'
end

AppDelegade.m

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

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo {
  [RNFirebaseMessaging didReceiveRemoteNotification:userInfo];
}

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

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
       willPresentNotification:(UNNotification *)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
  [RNFirebaseMessaging willPresentNotification:notification withCompletionHandler:completionHandler];
  
}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
         withCompletionHandler:(void (^)())completionHandler {
  [RNFirebaseMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}

Environment

  1. Application Target Platform: iOS
  1. Development Operating System: macOS Sierra
  1. Build Tools: Xcode 9.0.1
  1. React Native version: react-native-cli: 2.0.1 react-native: 0.47.2
  1. RNFirebase Version: "react-native-firebase": "^2.2.0"
  1. Firebase Module: Messaging

sharavana06 avatar Oct 31 '17 09:10 sharavana06

Please fill out the issue template correctly.

Ehesp avatar Oct 31 '17 10:10 Ehesp

Updated

sharavana06 avatar Nov 01 '17 06:11 sharavana06

Thanks for reporting. We're aware of lots of issues with notifications and will be addressing them all as part of the v3.2.0 release stream. Please see https://github.com/invertase/react-native-firebase/issues/595 for updates.

chrisbianca avatar Nov 08 '17 15:11 chrisbianca

im also facing this issue ..any heads up of how to go about ? only in ios foreground notification doesnt show up...android is good

rajeshzmoke avatar Feb 14 '18 05:02 rajeshzmoke

Good news, the long awaited alpha of our messaging and notifications overhaul is now available!!

Check out the release notes here: https://github.com/invertase/react-native-firebase/releases/tag/v4.0.0-alpha.1

If you have any comments and suggestions or want to report an issue, come find us on Discord

chrisbianca avatar Mar 20 '18 09:03 chrisbianca

I am also getting this issue and there seems no way to correct it if you are dealing with two notifications SDKs.

I am not using the default swizzling that most apps use with firebase because I have another notifications SDK integrated for customer support (similar to intercom). I'm using react-native-firebase 5.2.2, and it expects willPresentNotification to be called, through swizzling I presume. If the willPresentNotification could just be exposed in the RNFirebaseNotifications.h header, then it would allow users to fix this issue if they're not using swizzling by hitting it directly. @chrisbianca - does this seem possible?

wildseansy avatar Feb 20 '19 23:02 wildseansy

Nevermind, I was able to fix it with the following, routing willPresent back without swizzling

public func userNotificationCenter(_ center: UNUserNotificationCenter,
  willPresent notification: UNNotification,
  withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void
) {
    //...
    (RNFirebaseNotifications.instance() as! UNUserNotificationCenterDelegate).userNotificationCenter!(center, willPresent: notification, withCompletionHandler: completionHandler)

wildseansy avatar Feb 20 '19 23:02 wildseansy

Hi @wildseansy , do you know how to solve this in objective-C

LuongTruong avatar Jul 18 '19 02:07 LuongTruong