question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[iOS] Notification triggers when app opens (not working background/killed app)

See original GitHub issue

If the app is in foreground, the notification works fine. If the app is in the background, the notifications does not show, it triggers when the app opens. Same when the app is killed.

Device: iOS 9.3.5 real device on Release Mode react-native-fcm: 15.0.2

Podfile

platform :ios, '8.0'

target 'AppName' do
  pod 'AppsFlyerFramework'
  pod 'Firebase/Core'
  pod 'Firebase/Messaging'
  pod 'Firebase/Performance'
  pod 'Firebase/Crash'
  pod 'Firebase/RemoteConfig'
  pod 'FirebaseInstanceID'
  pod 'FirebaseMessaging'
  pod 'Fabric', '~> 1.7.2'
  pod 'Crashlytics', '~> 3.9.3'
  pod 'GoogleSignIn'
  pod 'GoogleAppUtilities'
  pod 'GoogleAuthUtilities'
  pod 'GoogleSymbolUtilities'
  pod 'GoogleUtilities'
  pod 'GoogleNetworkingUtilities'

  target 'AppNameTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

Podfile.lock

PODS:
  - AppsFlyerFramework (4.8.3)
  - Crashlytics (3.9.3):
    - Fabric (~> 1.7.2)
  - Fabric (1.7.5)
  - Firebase/Core (4.9.0):
    - FirebaseAnalytics (= 4.0.9)
    - FirebaseCore (= 4.0.15)
  - Firebase/Crash (4.9.0):
    - Firebase/Core
    - FirebaseCrash (= 2.0.2)
  - Firebase/Messaging (4.9.0):
    - Firebase/Core
    - FirebaseMessaging (= 2.1.0)
  - Firebase/Performance (4.9.0):
    - Firebase/Core
    - FirebasePerformance (= 1.1.1)
  - Firebase/RemoteConfig (4.9.0):
    - Firebase/Core
    - FirebaseRemoteConfig (= 2.1.2)
  - FirebaseABTesting (1.0.0):
    - FirebaseCore (~> 4.0)
    - Protobuf (~> 3.1)
  - FirebaseAnalytics (4.0.9):
    - FirebaseCore (~> 4.0)
    - FirebaseInstanceID (~> 2.0)
    - "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
    - nanopb (~> 0.3)
  - FirebaseCore (4.0.15):
    - "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
  - FirebaseCrash (2.0.2):
    - FirebaseAnalytics (~> 4.0)
    - FirebaseInstanceID (~> 2.0)
    - GoogleToolboxForMac/Logger (~> 2.1)
    - "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
    - Protobuf (~> 3.1)
  - FirebaseInstanceID (2.0.9):
    - FirebaseCore (~> 4.0)
  - FirebaseMessaging (2.1.0):
    - FirebaseAnalytics (~> 4.0)
    - FirebaseCore (~> 4.0)
    - FirebaseInstanceID (~> 2.0)
    - GoogleToolboxForMac/Logger (~> 2.1)
    - Protobuf (~> 3.1)
  - FirebasePerformance (1.1.1):
    - FirebaseAnalytics (~> 4.0)
    - FirebaseInstanceID (~> 2.0)
    - FirebaseSwizzlingUtilities (~> 1.0)
    - GoogleToolboxForMac/Logger (~> 2.1)
    - "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
    - GTMSessionFetcher/Core (~> 1.1)
    - Protobuf (~> 3.1)
  - FirebaseRemoteConfig (2.1.2):
    - FirebaseABTesting (~> 1.0)
    - FirebaseAnalytics (~> 4.0)
    - FirebaseCore (~> 4.0)
    - FirebaseInstanceID (~> 2.0)
    - "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
    - Protobuf (~> 3.1)
  - FirebaseSwizzlingUtilities (1.0.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.3):
    - GoogleToolboxForMac/Defines (= 2.1.3)
  - GoogleToolboxForMac/Defines (2.1.3)
  - GoogleToolboxForMac/Logger (2.1.3):
    - GoogleToolboxForMac/Defines (= 2.1.3)
  - "GoogleToolboxForMac/NSData+zlib (2.1.3)":
    - GoogleToolboxForMac/Defines (= 2.1.3)
  - "GoogleToolboxForMac/NSDictionary+URLArguments (2.1.3)":
    - GoogleToolboxForMac/DebugUtils (= 2.1.3)
    - GoogleToolboxForMac/Defines (= 2.1.3)
    - "GoogleToolboxForMac/NSString+URLArguments (= 2.1.3)"
  - "GoogleToolboxForMac/NSString+URLArguments (2.1.3)"
  - GoogleUtilities (1.3.2):
    - GoogleSymbolUtilities (~> 1.1)
  - GTMOAuth2 (1.1.6):
    - GTMSessionFetcher (~> 1.1)
  - GTMSessionFetcher (1.1.14):
    - GTMSessionFetcher/Full (= 1.1.14)
  - GTMSessionFetcher/Core (1.1.14)
  - GTMSessionFetcher/Full (1.1.14):
    - GTMSessionFetcher/Core (= 1.1.14)
  - 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)

AppDelegate.m

#import "AppDelegate.h"

#import <React/RCTLinkingManager.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RNSentry.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#import <RNGoogleSignin/RNGoogleSignin.h>
#import "SplashScreen.h"
#import <CodePush/CodePush.h>
#import <AppsFlyerLib/AppsFlyerTracker.h>
#import "RNFIRMessaging.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];

  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)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
  [RNFIRMessaging willPresentNotification:notification withCompletionHandler:completionHandler];
}

#if defined(__IPHONE_11_0)
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
{
  [RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
#else
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler
{
  [RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
#endif

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

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

- (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

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

Notes: I’m also using react-native-firebase 4.1.0

Any ideas?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
maggialejandrocommented, Jun 8, 2018

I ended up switching to react-native-firebase, which had the same problem, fixed it by removing FirebaseAppDelegateProxyEnabled from Info.plist

0reactions
yusuf987commented, Apr 6, 2019

exact same issue with me too, please somebody help

Read more comments on GitHub >

github_iconTop Results From Across the Web

onNotification not being triggered when app is killed #1555
With the above payload I am able to receive notifications in all app states (foreground/background/killed) but it was not triggering the ...
Read more >
IOS Push notification actions when app is killed/closed/not open
Whenever you apps awakes from killed/closed/not open state. The didReceiveNotification will not be called instead didFinishLaunching will be ...
Read more >
Remote push notification doesn't wake up app
We noticed that it works when the app is in background but that when the app moves from background to suspended (Apple decides...
Read more >
How to Set up Push Notifications in React Native - Around25
Which you can do by opening your /ios/{projectName}/AppDelegate.m file, ... To receive push notifications on iOS, the app has to request ...
Read more >
Notifications Not Shown - Mobile Push
Common reasons why Mobile Push notifications are not showing on your device. ... Android,iOS: In your Device Settings > Notifications > Your App, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found