Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS][Notifications] does not work when app is killed / background #1179

Closed
maggialejandro opened this issue Jun 5, 2018 · 11 comments
Closed

Comments

@maggialejandro
Copy link

Issue

The Push Notification does arrive when the app is in background or killed.
It is received when app is next opened.

PODS:
  - AppsFlyerFramework (4.8.5)
  - Crashlytics (3.9.3):
    - Fabric (~> 1.7.2)
  - Fabric (1.7.7)
  - Firebase/Core (5.0.1):
    - Firebase/CoreOnly
    - FirebaseAnalytics (= 5.0.0)
  - Firebase/CoreOnly (5.0.1):
    - FirebaseCore (= 5.0.1)
  - Firebase/Crash (5.0.1):
    - Firebase/Core
    - FirebaseCrash (= 3.0.0)
  - Firebase/Messaging (5.0.1):
    - Firebase/CoreOnly
    - FirebaseMessaging (= 3.0.0)
  - Firebase/Performance (5.0.1):
    - Firebase/Core
    - FirebasePerformance (= 2.0.0)
  - Firebase/RemoteConfig (5.0.1):
    - Firebase/Core
    - FirebaseRemoteConfig (= 3.0.0)
  - FirebaseABTesting (2.0.0):
    - FirebaseCore (~> 5.0)
    - Protobuf (~> 3.5)
  - FirebaseAnalytics (5.0.0):
    - FirebaseCore (~> 5.0)
    - FirebaseInstanceID (~> 3.0)
    - "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
    - nanopb (~> 0.3)
  - FirebaseCore (5.0.1):
    - "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
  - FirebaseCrash (3.0.0):
    - FirebaseAnalytics (~> 5.0)
    - FirebaseInstanceID (~> 3.0)
    - GoogleToolboxForMac/Logger (~> 2.1)
    - "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
    - Protobuf (~> 3.5)
  - FirebaseInstanceID (3.0.0):
    - FirebaseCore (~> 5.0)
  - FirebaseMessaging (3.0.0):
    - FirebaseCore (~> 5.0)
    - FirebaseInstanceID (~> 3.0)
    - GoogleToolboxForMac/Logger (~> 2.1)
    - Protobuf (~> 3.1)
  - FirebasePerformance (2.0.0):
    - FirebaseAnalytics (~> 5.0)
    - FirebaseInstanceID (~> 3.0)
    - FirebaseSwizzlingUtilities/ISASwizzling (~> 2.0)
    - FirebaseSwizzlingUtilities/MethodSwizzling (~> 2.0)
    - GoogleToolboxForMac/Logger (~> 2.1)
    - "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
    - GTMSessionFetcher/Core (~> 1.1)
    - Protobuf (~> 3.5)
  - FirebaseRemoteConfig (3.0.0):
    - FirebaseABTesting (~> 2.0)
    - FirebaseAnalytics (~> 5.0)
    - FirebaseCore (~> 5.0)
    - FirebaseInstanceID (~> 3.0)
    - "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
    - Protobuf (~> 3.5)
  - FirebaseSwizzlingUtilities/ISASwizzling (2.0.0)
  - FirebaseSwizzlingUtilities/MethodSwizzling (2.0.0):
    - FirebaseCore (~> 5.0)
  - GoogleAppUtilities (1.1.2):
    - GoogleSymbolUtilities (~> 1.1)
  - GoogleAuthUtilities (2.0.2):
    - GoogleNetworkingUtilities (~> 1.2)
    - GoogleSymbolUtilities (~> 1.1)
  - GoogleNetworkingUtilities (1.2.2):
    - GoogleSymbolUtilities (~> 1.1)
  - GoogleSignIn (4.1.2):
    - "GoogleToolboxForMac/NSDictionary+URLArguments (~> 2.1)"
    - "GoogleToolboxForMac/NSString+URLArguments (~> 2.1)"
    - GTMOAuth2 (~> 1.0)
    - GTMSessionFetcher/Core (~> 1.1)
  - GoogleSymbolUtilities (1.1.2)
  - GoogleToolboxForMac/DebugUtils (2.1.4):
    - GoogleToolboxForMac/Defines (= 2.1.4)
  - GoogleToolboxForMac/Defines (2.1.4)
  - GoogleToolboxForMac/Logger (2.1.4):
    - GoogleToolboxForMac/Defines (= 2.1.4)
  - "GoogleToolboxForMac/NSData+zlib (2.1.4)":
    - GoogleToolboxForMac/Defines (= 2.1.4)
  - "GoogleToolboxForMac/NSDictionary+URLArguments (2.1.4)":
    - GoogleToolboxForMac/DebugUtils (= 2.1.4)
    - GoogleToolboxForMac/Defines (= 2.1.4)
    - "GoogleToolboxForMac/NSString+URLArguments (= 2.1.4)"
  - "GoogleToolboxForMac/NSString+URLArguments (2.1.4)"
  - GoogleUtilities (1.3.2):
    - GoogleSymbolUtilities (~> 1.1)
  - GTMOAuth2 (1.1.6):
    - GTMSessionFetcher (~> 1.1)
  - GTMSessionFetcher (1.1.15):
    - GTMSessionFetcher/Full (= 1.1.15)
  - GTMSessionFetcher/Core (1.1.15)
  - GTMSessionFetcher/Full (1.1.15):
    - GTMSessionFetcher/Core (= 1.1.15)
  - nanopb (0.3.8):
    - nanopb/decode (= 0.3.8)
    - nanopb/encode (= 0.3.8)
  - nanopb/decode (0.3.8)
  - nanopb/encode (0.3.8)
  - Protobuf (3.5.0)

DEPENDENCIES:
  - AppsFlyerFramework
  - Crashlytics (~> 3.9.3)
  - Fabric (~> 1.7.2)
  - Firebase/Core
  - Firebase/Crash
  - Firebase/Messaging
  - Firebase/Performance
  - Firebase/RemoteConfig
  - FirebaseInstanceID
  - FirebaseMessaging
  - GoogleAppUtilities
  - GoogleAuthUtilities
  - GoogleNetworkingUtilities
  - GoogleSignIn
  - GoogleSymbolUtilities
  - GoogleUtilities

SPEC REPOS:
  https://github.com/cocoapods/specs.git:
    - AppsFlyerFramework
    - Crashlytics
    - Fabric
    - Firebase
    - FirebaseABTesting
    - FirebaseAnalytics
    - FirebaseCore
    - FirebaseCrash
    - FirebaseInstanceID
    - FirebaseMessaging
    - FirebasePerformance
    - FirebaseRemoteConfig
    - FirebaseSwizzlingUtilities
    - GoogleAppUtilities
    - GoogleAuthUtilities
    - GoogleNetworkingUtilities
    - GoogleSignIn
    - GoogleSymbolUtilities
    - GoogleToolboxForMac
    - GoogleUtilities
    - GTMOAuth2
    - GTMSessionFetcher
    - nanopb
    - Protobuf

SPEC CHECKSUMS:
  AppsFlyerFramework: cf9fdd7367a3871542f46b75b56723395553f951
  Crashlytics: dbb07d01876c171c5ccbdf7826410380189e452c
  Fabric: bda89e242bce1b7b8ab264248cf3407774ce0095
  Firebase: d6861c2059d8c32d1e6dd8932e22ada346d90a3a
  FirebaseABTesting: 1f50b8d50f5e3469eea54e7463a7b7fe221d1f5e
  FirebaseAnalytics: 19812b49fa5f283dd6b23edf8a14b5d477029ab8
  FirebaseCore: cafc814b2d84fc8733f09e653041cc2165332ad7
  FirebaseCrash: 8900571fd763fd5bdda04522ec53da979456e3ce
  FirebaseInstanceID: 83e0040351565df711a5db3d8ebe5ea21aca998a
  FirebaseMessaging: f2360a966ecfb0d14facf0fbdf306efc2df0ddbe
  FirebasePerformance: 1ec6c40e5dad2543ca4c4f25d15168bde6322c2c
  FirebaseRemoteConfig: 3c57e4644bd6976b671ae0b725cd709f198bd1f5
  FirebaseSwizzlingUtilities: 6c22677c50d0b6f5f0dc637c1233f13694a3003f
  GoogleAppUtilities: a8a552aa74f6597f805e45b5a3962766c3134973
  GoogleAuthUtilities: ccad2e0a9284699973ff57c0dd24c3893657fda4
  GoogleNetworkingUtilities: 3edd3a8161347494f2da60ea0deddc8a472d94cb
  GoogleSignIn: d9ef55b10f0aa401a5de2747f59b725e4b9732ac
  GoogleSymbolUtilities: 631ee17048aa5e9ab133470d768ea997a5ef9b96
  GoogleToolboxForMac: 91c824d21e85b31c2aae9bb011c5027c9b4e738f
  GoogleUtilities: 8bbc733218aad26306f9d4a253823986110e3358
  GTMOAuth2: c77fe325e4acd453837e72d91e3b5f13116857b2
  GTMSessionFetcher: 5fa5b80fd20e439ef5f545fb2cb3ca6c6714caa2
  nanopb: 5601e6bca2dbf1ed831b519092ec110f66982ca3
  Protobuf: 8a9838fba8dae3389230e1b7f8c104aa32389c03

PODFILE CHECKSUM: 8db2444829a197d3b1ef484abfd469f594d2ada1

COCOAPODS: 1.5.3

AppDelegate.m

#import "AppDelegate.h"

#import <React/RCTLinkingManager.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#if __has_include(<React/RNSentry.h>)
#import <React/RNSentry.h> // This is used for versions of react >= 0.40
#else
#import "RNSentry.h" // This is used for versions of react < 0.40
#endif
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#import <RNGoogleSignin/RNGoogleSignin.h>
#import "SplashScreen.h"
#import <CodePush/CodePush.h>
#import <AppsFlyerLib/AppsFlyerTracker.h>
#import <Firebase.h>
#import "RNFirebaseNotifications.h"
#import "RNFirebaseMessaging.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [FIRApp configure];
  [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];

  NSURL *jsCodeLocation;

  #ifdef DEBUG
    jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
  #else
    jsCodeLocation = [CodePush bundleURL];
  #endif

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"AppName"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];

  [RNSentry installWithRootView:rootView];

  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];

  [SplashScreen show];
  [RNFirebaseNotifications configure];

  return [[FBSDKApplicationDelegate sharedInstance] application:application
                                  didFinishLaunchingWithOptions:launchOptions];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
  [FBSDKAppEvents activateApp];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {

  return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                        openURL:url
                                              sourceApplication:sourceApplication
                                                     annotation:annotation
          ]
  || [RNGoogleSignin application:application
                         openURL:url
               sourceApplication:sourceApplication
                      annotation:annotation
      ]
  || [RCTLinkingManager application:application openURL:url
               sourceApplication:sourceApplication annotation:annotation];
}

- (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];
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(nonnull NSData *)deviceToken{
  [[AppsFlyerTracker sharedTracker] registerUninstall:deviceToken];
}

@end

AppDelegate.h

#import <UIKit/UIKit.h>

@import UserNotifications;

@interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>

@property (nonatomic, strong) UIWindow *window;

@end

captura de pantalla 2018-05-29 a la s 11 57 39

captura de pantalla 2018-05-29 a la s 11 57 26

FCM Payload

$post = [
  'to' => $to,
  'priority' => 'high',
  'content_available' => true,
  'show_in_foreground' => true,
  
  'notification' => array(
    'time_to_live' => 172800,
    "sound" => "default",
    "lights" => true,
    'title' => $notification['title'],
    'body'  => $notification['body'],
    'tag'   => $notification['id'],
    'color' => '#3f78c3',
    'priority' => 'high',
    'icon'      => 'ic_notif',
    'image'     => 'ic_launcher',
    'largeIcon' => 'ic_launcher',
    'smallIcon' => 'ic_launcher'
  ),

  'data' => [
    'notificationId' => $notification['notificationId'],
    'title' => $notification['title'],
    'body'  => $notification['body'],
    'iso' => $notification['iso'],
    'image' => 'ic_launcher',
    'click_action'  => $notification['url'],
  ]
];

any ideas?
Thanks in advance

Environment

iOS 9.3.5 Real Device on Release Mode
react-native-firebsse 4.2.0
react-native 0.53.3
XCode 9.1
MacOS 10.13.5

@maggialejandro
Copy link
Author

Fixed it by removing FirebaseAppDelegateProxyEnabled from Info.plist

@DexterHuang
Copy link

@maggialejandro hey, I have removed FirebaseAppDelegateProxyEnabled from my info.plist,
but the situation is still the same... only received the notification when the app is in the foreground...

@henrycity
Copy link

henrycity commented Aug 1, 2018

@maggialejandro solution worked for me.

@ananth10
Copy link

Hello , I am also facing similar issue. notification did not receive when IOS app in background/closed.
please anyone provide working solution. Thanks in advance.

@andreififiita
Copy link

Hello, I am having the same issue with data messages, but only when the app is killed. When it is in background it works fine. Also, I do not have a FirebaseAppDelegateProxyEnabled entry in my Info.plist.

@ghost
Copy link

ghost commented Nov 21, 2018

@andreififiita Did you find any solution for app killed issue.??

@reaction reaction bot deleted a comment Nov 21, 2018
@laukaichung
Copy link

@maggialejandro
I don't have FirebaseAppDelegateProxyEnabled in Info.plist and the notification doesn't work in the background.

@phonganhhung9xtb
Copy link

when app killed, i cannot open my notification, seem app crashed immediate click on notfication. any update? i'm using ios device.

@faustoct1
Copy link

@pheromonez to me it's like happens the same.. the app does not crash but it's put launched and put in background..

@moulie415
Copy link

moulie415 commented Jul 13, 2019

Screenshot 2019-07-14 at 00 31 25

Seems on iOS the notification won't be received instantly when app is killed, only when it is next opened. See the docs: https://rnfirebase.io/docs/v5.x.x/messaging/introduction

@seunex
Copy link

seunex commented Jul 27, 2019

When the app is in Background, You should get a notification when you set
'registration_ids' => '', 'data' => '', 'priority' => "high" , 'content_available' => true //this

@moulie415 image helped too. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants