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

Notification not more received in IOS after the App close #2192

Closed
2 of 7 tasks
Nerogee opened this issue Jun 3, 2019 · 12 comments
Closed
2 of 7 tasks

Notification not more received in IOS after the App close #2192

Nerogee opened this issue Jun 3, 2019 · 12 comments
Labels
Type: Stale Issue has become stale - automatically added by Stale bot

Comments

@Nerogee
Copy link

Nerogee commented Jun 3, 2019

Issue

I managed to generate fcm token and pushing notification while my iphone device can receive successfully. In my app, I always perform firebase.messaging().deleteToken() and firebase.messaging.getToken() each time a user login or when a user changes his profile setting whether to receive notification or not (this is the app logic). And this behavior works fine, each time I login, I get a new fcm token and save it in my database. The token is working fine. The problem happens when I close my app and reopen it again. though I can still get a new fcm token after perform a login, that token is not working. By not working, I mean when I test the new token through postman, I get successful response, but my iphone device does not receive anything. That is weird.

However, if I turn off the device notification permission in IOS system settings, then go back to my app and toggle the notification setting in user profile which will in return check permission again. In the permission popup, I implement a button that redirects a user to IOS notification settings. Once I turn on the permission in device setting and back to my app to let it generate a new fcm token. It works again.

does any solution or explanation to this issue? I found some people said the notification stop working after some time. Is it the same issue here?

P.S. In Android, it works fine.


Project Files

iOS

Click To Expand

ios/Podfile:

  • I'm not using Pods
  • I'm using Pods and my Podfile looks like:
# Uncomment the next line to define a global platform for your project
 platform :ios, '9.0'

pod 'Firebase/Core', '~> 5.20.1'
pod 'Firebase/Messaging', '~> 5.20.1'

target 'Dozenbird' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for Dozenbird

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

end

target 'Dozenbird-tvOS' do
  # Comment the next line if you don't want to use dynamic frameworks
  # use_frameworks!

  # Pods for Dozenbird-tvOS

  target 'Dozenbird-tvOSTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

AppDelegate.m:

/**
 * 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 <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RCTLinkingManager.h>
#import <Firebase.h>
#import "RNFirebaseNotifications.h"
#import "RNFirebaseMessaging.h"


@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [FIRApp configure];
  [RNFirebaseNotifications configure];
  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"Dozenbird"
                                            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];
  
  UIView* launchScreenView = [[[NSBundle mainBundle] loadNibNamed:@"LaunchScreen" owner:self options:nil] objectAtIndex:0];
  launchScreenView.frame = self.window.bounds;
  rootView.loadingView = launchScreenView;
  
  return YES;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
  //return [NSURL URLWithString:@"http://192.168.31.93:8081/index.bundle?platform=ios"];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}


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

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
  return [RCTLinkingManager application:application openURL:url
                      sourceApplication:sourceApplication annotation:annotation];
}

@end


Android

Click To Expand

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:

System:
      OS: macOS 10.14.5
      CPU: (4) x64 Intel(R) Core(TM) m3-6Y30 CPU @ 0.90GHz
      Memory: 41.33 MB / 8.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.15.3 - /usr/local/bin/node
      npm: 6.4.1 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
    IDEs:
      Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3 
      react-native: 0.59.4 => 0.59.4 
    npmGlobalPackages:
      react-native-cli: 2.0.1
  • Platform that you're experiencing the issue on:
    • iOS
    • Android
    • iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • Firebase module(s) you're using that has the issue:
    • e.g. Instance ID
  • Are you using TypeScript?
    • Y/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]

@mikehardy
Copy link
Collaborator

Notification stuff is notoriously complicated. I'd have to see reproducible example in a repo on github

@Nerogee
Copy link
Author

Nerogee commented Jun 3, 2019

Yes, I totally understand that it's complicated.
I poked around and have bellow findings:
I also have my comment in this post #1900 (comment)

FOUR weird things,

  1. after close and reopen the app, and the first time to have a login which I expect it returns a new fcm token but it does not. It give me the same token as I had before closing the app.
  2. Try logout and login again, it now returns a new fcm token.
  3. This new fcm token can be used to push notification with SUCCESSFUL return. BUT, it ONLY triggers the firebase.messaging().onMessage(), but I would expect it trigger the firebase.notifications().onNotification
  4. If I go to IOS settings to turn off notification permission and back to my app to toggle notification permission (this is app feature itself which is to allow user to control if he wants to receive notification or not). The feature check system permission first and a button in popup that can redirect user to system settings if permission is not granted, which is exactly the case I want to test. When at system permission screen, enable the notification. Then back to my app, enable the (In app) notification, this time there won't have permission popup as I just enable it at system settings. OK. It now starts to work normal, UNTIL I close my app and conduct another logout and login. (back to step 1 again)

@stale
Copy link

stale bot commented Jul 1, 2019

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 stale bot added the Type: Stale Issue has become stale - automatically added by Stale bot label Jul 1, 2019
@timhonders
Copy link

I have the same issue on version 5.3.1.

@stale stale bot removed the Type: Stale Issue has become stale - automatically added by Stale bot label Jul 5, 2019
@Nerogee
Copy link
Author

Nerogee commented Jul 5, 2019

@timhonders, I solved most of the problem by always conduct a request permission call before register a series of notification listeners. It’s mentioned in documents but not that obvious. Especially in my case, I don’t want to prompt user at the very first time the app is open, but rather until it comes to a special point.

I think we need some real life working example in a more comprehensive way in the context of react native. Current documents provide just separated snippets which is not very clear and helpful to people new to this tool.

@mikehardy
Copy link
Collaborator

I completely agree we need an example - I've started with https://github.com/mikehardy/rnfbdemo/blob/master/make-demo.sh and I'd love for the App.js there to have the ability to show scenarios in an easy way. I will happily accept pull requests there and add collaborators, and as I maintain the v5 branch I'll keep it up to date, but I haven't had time to implement feature demos yet - just building was hard enough!

@timhonders
Copy link

@Nerogee I found an other workaround you could call firebase.messaging().ios.registerForRemoteNotifications().

This wil fix the issue without the need to call requestPermission.

I will go with youre fix, thnx

@louisch
Copy link

louisch commented Jul 9, 2019

Can confirm that I do not receive notifications on ios with the app in the background, and additionally, that I getAPNSToken returns null (not the FCM token though), unless I call firebase.messaging().ios.registerForRemoteNotifications()

@stale
Copy link

stale bot commented Aug 7, 2019

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 stale bot added the Type: Stale Issue has become stale - automatically added by Stale bot label Aug 7, 2019
@stale
Copy link

stale bot commented Aug 22, 2019

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 stale bot closed this as completed Aug 22, 2019
@AdeilsonSuperlogica
Copy link

@Nerogee I found an other workaround you could call firebase.messaging().ios.registerForRemoteNotifications().

This wil fix the issue without the need to call requestPermission.

I will go with youre fix, thnx

Working for me... tks....

@Stas-Buzunko
Copy link
Contributor

#1203 (comment) worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Stale Issue has become stale - automatically added by Stale bot
Projects
None yet
Development

No branches or pull requests

6 participants