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

getInitialNotification is always returning null #24

Open
filipecrosk opened this issue Sep 5, 2019 · 28 comments
Open

getInitialNotification is always returning null #24

filipecrosk opened this issue Sep 5, 2019 · 28 comments

Comments

@filipecrosk
Copy link

filipecrosk commented Sep 5, 2019

Bug

I can't get getInitialNotification() to work, its always returning null. Regular notification when the app is already open is working fine, but if the app is closed and I receive a new notification it will ways return null for me.

Environment info

React native info output:

System:
    OS: macOS 10.14.6
    CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
    Memory: 1.39 GB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 8.10.0 - ~/.nvm/versions/node/v8.10.0/bin/node
    Yarn: 1.17.0 - /usr/local/bin/yarn
    npm: 5.6.0 - ~/.nvm/versions/node/v8.10.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
    Android SDK:
      API Levels: 28
      Build Tools: 28.0.3, 29.0.1
      System Images: android-Q | Google Play Intel x86 Atom
  IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5692245
    Xcode: 10.3/10G8 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6
    react-native: 0.60.4 => 0.60.4
  npmGlobalPackages:
    react-native-cli: 2.0.1

Library version: 1.0.2

Steps To Reproduce

  1. Install the library
  2. Add all settings to AppDelegate.m
  3. Add code to your app
  4. Send a notification
componentDidMount() {
    PushNotificationIOS.addEventListener('notification', function(notification) {
      console.log('Log - notification is open', notification);
      if (!notification) {
        return;
      }
      const data = notification.getData();
      Alert.alert(JSON.stringify({ data, source: 'CollapsedApp' }));
    });

    PushNotificationIOS.getInitialNotification().then(notification => {
      console.log('Log - notification from closed', notification);
      if (!notification) {
        return;
      }
      const data = notification.getData();
      Alert.alert(JSON.stringify({ data, source: 'ClosedApp' }));
    });
    PushNotificationIOS.requestPermissions();
  }

...

A code sample can be found here https://github.com/filipecrosk/react-native-push-notification-ios-test

@Linoa65
Copy link

Linoa65 commented Sep 20, 2019

Same here, tried with 3 different methods (RNCPushNotificationIOS, RNFirebase & RN-Push-Notification) and unable to get this initial notification when I click on notification to open app. It seems there is a problem there...

Hope someone will help us ! :)

@danielzzz
Copy link

danielzzz commented Sep 25, 2019

yep, the promise always returns null after a cold start.

@ingiulio
Copy link

ingiulio commented Oct 1, 2019

Same here:

React Native Environment Info:
    System:
      OS: macOS 10.14.4
      CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
      Memory: 68.46 MB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 8.11.1 - /usr/local/bin/node
      npm: 5.7.1 - ~/.nvm/versions/node/v8.11.1/bin/npm
    SDKs:
      iOS SDK:
        Platforms: iOS 13.0, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
    IDEs:
      Xcode: 11.0/11A420a - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3
      react-native: 0.59.8 => 0.59.8
    npmGlobalPackages:
      react-native-cli: 2.0.1

Appreciate the help!

@phoenix377
Copy link

Same here. It always returns null.

@tlow92
Copy link

tlow92 commented Oct 31, 2019

anyone found a workaround?

@cmoel
Copy link

cmoel commented Oct 31, 2019

I found this to be a problem when the Scheme's Build Configuration is set to Debug but not when it's set to Release. I'm using React Native 0.59.9 and not using this library yet.

Details

At least in my case, through some digging in Objective-C, I found that two React Native bridges were created when doing a Debug build, while only one was created for a Release build. For Debug, the initial notification was included in the first bridge's bridge.launchOptions (ref) while bridge.launchOptions was nil for the second instance. I added some debugging statements in RCTBridge's setUp method, which is how I discovered it was being called twice.

I then changed the Scheme's Build Configuration to Release and tried again. Only one React Native bridge was created and PushNotificationIOS.getInitialNotification returned the notification I used to launch the app.

@tlow92
Copy link

tlow92 commented Nov 1, 2019

I found this to be a problem when the Scheme's Build Configuration is set to Debug but not when it's set to Release. I'm using React Native 0.59.9 and not using this library yet.

Details

At least in my case, through some digging in Objective-C, I found that two React Native bridges were created when doing a Debug build, while only one was created for a Release build. For Debug, the initial notification was included in the first bridge's bridge.launchOptions (ref) while bridge.launchOptions was nil for the second instance. I added some debugging statements in RCTBridge's setUp method, which is how I discovered it was being called twice.

I then changed the Scheme's Build Configuration to Release and tried again. Only one React Native bridge was created and PushNotificationIOS.getInitialNotification returned the notification I used to launch the app.

Thanks for the input.

Maybe it's because I am using RN 0.61.1, but even in release configuration getInitialNotification is always returning null.

@shanemduggan
Copy link

Seeing the same thing on RN 0.59.8.

@tlow92
Copy link

tlow92 commented Nov 7, 2019

Only solution is to use react-native-firebase, but i don't want to introduce it only for detecting opening of push notifications and it has its own problems, like receiving device token etc.

Libraries like zo0r/react-native-push-notification also don't work because they depend on this project here.

If someone has a hint, what the underlying problem could be, I'm happy to take a look into it.

@mkarazin
Copy link

I had this issue and solved it, at least enough for my needs.

On RN 0.59.10, running locally on a device using a dev/debug build (hot reload, debugger running) all calls to getInitialNotification returned null. Following @cmoel comment, I created a release build and distributed the .ipa to my test device. It worked fully there, with push notifications to a closed app as well as a backgrounded app. getInitialNotification would return the notification correctly, using exactly the same code as I ran in the dev/debug build.

Obviously this isn't ideal. It would be great to be able to received initial notifications on a dev build with debugger and hot reload working. I'm wondering if this isn't really a bug but is actually an issue with how react-native loads the js bundle. In my dev build, whenever the app is opened from closed state, the js bundle is redownloaded. Perhaps this is in essence opening the app twice, and the initial notification is not available by the time it opens fully.

@acro5piano
Copy link

acro5piano commented Dec 19, 2019

Same here. I'm trying to find any solutions.

I read both Obj-C and JS, and found this line:

https://github.com/react-native-community/react-native-push-notification-ios/blob/master/ios/RNCPushNotificationIOS.m#L411

I don't know Obj-c much, but do you think this change will make a difference?

- NSMutableDictionary<NSString *, id> *initialNotification =
-  [self.bridge.launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] mutableCopy];
+  [[self.bridge.launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey] mutableCopy];

@nighttiger1990
Copy link

Same here, in RN 61.5. Hope someone fix this

@acro5piano
Copy link

disabling Debug JS Remotely solved the issue for me.

@dominiczaq
Copy link

getInitialNotification only returns data when the app is starting from cold boot. Additionally it won't return data in development build, but it will in release build.

@opula
Copy link

opula commented Mar 6, 2020

Has only figured out a workaround? I'm using this library in conjunction with aws amplify (which requires the community version). Prior to a few weeks ago, we we're using an older version of amplify (which used the built in PushNotificationIOS) and this worked fine.

Haven't figured out a way yet to get this to return anything but null (debug or release).

@dominiczaq
Copy link

dominiczaq commented Mar 6, 2020

Haven't figured out a way yet to get this to return anything but null (debug or release).

Did you check notification from coldboot? This method only returns notification which was fired while coldbooting, it won't show other notifications. Use 'notification' event for that.

@opula
Copy link

opula commented Mar 6, 2020

@dominiczaq Yes, that's the one that returns null. Notifications coming in while mobile locked or in the background are okay. The getInitialNotification event is fired, but the data is null.

@shanemduggan
Copy link

shanemduggan commented Mar 9, 2020

We ended up writing native code to handle this since it wasn't working with the library. Hope this helps.

JS Helper
async function getInitialNotification() { if (Platform.OS === 'ios') { return await NativeModules.NativeHelpers.getInitialNotification(); } return null; }

Swift
@objc func getInitialNotification(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) { let launchOptions = (UIApplication.shared.delegate as! AppDelegate).launchOptions let notification = launchOptions?[UIApplication.LaunchOptionsKey.remoteNotification] resolve(notification) }

Objective-C
#import <React/RCTBridgeModule.h> @interface RCT_EXTERN_MODULE(NativeHelpers, NSObject) RCT_EXTERN_METHOD(getInitialNotification:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) (dispatch_queue_t)methodQueue {return dispatch_get_main_queue();} (BOOL)requiresMainQueueSetup { return YES;} @end

@opula
Copy link

opula commented Mar 11, 2020

@shanemduggan Do you think you could post a gist with this code? I tried to implement, but I'm running to an issue. I'm not super versed in obj-c / swift so that's probably the problem.

@shanemduggan
Copy link

@opula I'm not well versed in it either but I threw a gist together that should be more helpful. The swift and obj-c files go in 'ios/app name/Native' folder. here ya go - https://gist.github.com/shanemduggan/b22c60fa1d0bacf364c91e83efe0926c

chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Jun 17, 2020
Some (rather rude! yet still disregarded and closed-as-stale)
comments [1] on wix/react-native-notifications report that it's a
shame to see a decrease in activity from the maintainers, since it's
the only viable cross-platform library for RN push notifications.

But we don't even use it in a cross-platform way; we uprooted the
last of the linking logic on Android in 01b33ad. It also seems
strange to have two different libraries doing work to support push
notifications on iOS. See also discussion [2].

So, let PushNotificationIOS from react-native take responsibility
for what this library has been doing. Then, since *that's*
deprecated, an upcoming commit will have us using that same code but
from react-native-community, where it's maintained.

These were my steps:

1. Use the setup instructions for our version of
   `react-native-notifications` [3] to tear it down.

2. Use the setup instructions for `PushNotificationIOS` [4] from RN
   v0.60 to complete our setup. Some parts were missing, whether
   because we didn't need that functionality before, or it wasn't
   available in earlier RN versions.

3. Change the bit under the comment "Called when a notification is
   delivered to a foreground app." to correctly call the completion
   handler with UNNotificationPresentationOptions instead of
   UNAuthorizationOptions. N.B.: Also, remove the options that ask
   it to play a sound and show an alert, as these aren't part of the
   current behavior. That just leaves updating the badge count.

4. Make tiny, NFC adjustments, mostly to indentation, to smooth the
   transition to the react-native-community module.

5. Change the call sites to use PushNotificationIOS, and update some
   types and comments. One part that stands out is the removal of
   the "consumeBackgroundQueue" hack from c0e2233. Nothing further
   is necessary, it just works. :)

6. Do various housekeeping things like removing the libdef.

7. On iOS, test that notifications still appear in the closed and
   background states and that, from either state, they navigate to
   the corresponding narrow. All works as expected, with one
   "gotcha": from a cold start, in debug mode, sometimes
   notifications don't navigate. There's an open issue for this [5],
   and it seems it doesn't affect release builds. In debug mode, I
   was able to solve it by disabling "Debug JS Remotely", following
   one comment there. In any case, `getInitialNotification` is what
   we've already been using PushNotificationIOS for, for a long
   time, so this hiccup is not new.

8. On Android, test that notifications appear (regardless of
   closed/background/foreground state) and navigate to the
   corresponding narrow.

[1]: wix/react-native-notifications#519 (comment)
[2]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.20push.20notifications/near/825122
[3]: https://github.com/wix/react-native-notifications/blob/882775fb5/docs/installation.md
[4]: https://reactnative.dev/docs/0.60/pushnotificationios
[5]: react-native-push-notification/ios#24 (comment)
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Jul 13, 2020
Some (rather rude! yet still disregarded and closed-as-stale)
comments [1] on wix/react-native-notifications report that it's a
shame to see a decrease in activity from the maintainers, since it's
the only viable cross-platform library for RN push notifications.

But we don't even use it in a cross-platform way; we uprooted the
last of the linking logic on Android in 01b33ad. It also seems
strange to have two different libraries doing work to support push
notifications on iOS. See also discussion [2].

So, let PushNotificationIOS from react-native take responsibility
for what this library has been doing. Then, since *that's*
deprecated, an upcoming commit will have us using that same code but
from react-native-community, where it's maintained.

These were my steps:

1. Use the setup instructions for our version of
   `react-native-notifications` [3] to tear it down.

2. Use the setup instructions for `PushNotificationIOS` [4] from RN
   v0.60 to complete our setup. Some parts were missing, whether
   because we didn't need that functionality before, or it wasn't
   available in earlier RN versions.

3. Change the bit under the comment "Called when a notification is
   delivered to a foreground app." to correctly call the completion
   handler with UNNotificationPresentationOptions instead of
   UNAuthorizationOptions. N.B.: Also, remove the options that ask
   it to play a sound and show an alert, as these aren't part of the
   current behavior. That just leaves updating the badge count.

4. Make tiny, NFC adjustments, mostly to indentation, to smooth the
   transition to the react-native-community module.

5. Change the call sites to use PushNotificationIOS, and update some
   types and comments. One part that stands out is the removal of
   the "consumeBackgroundQueue" hack from c0e2233. Nothing further
   is necessary, it just works. :)

6. Do various housekeeping things like removing the libdef.

7. On iOS, test that notifications still appear in the closed and
   background states and that, from either state, they navigate to
   the corresponding narrow. All works as expected, with one
   "gotcha": from a cold start, in debug mode, sometimes
   notifications don't navigate. There's an open issue for this [5],
   and it seems it doesn't affect release builds. In debug mode, I
   was able to solve it by disabling "Debug JS Remotely", following
   one comment there. In any case, `getInitialNotification` is what
   we've already been using PushNotificationIOS for, for a long
   time, so this hiccup is not new.

8. On Android, test that notifications appear (regardless of
   closed/background/foreground state) and navigate to the
   corresponding narrow.

[1]: wix/react-native-notifications#519 (comment)
[2]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.20push.20notifications/near/825122
[3]: https://github.com/wix/react-native-notifications/blob/882775fb5/docs/installation.md
[4]: https://reactnative.dev/docs/0.60/pushnotificationios
[5]: react-native-push-notification/ios#24 (comment)
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Sep 16, 2020
Some (rather rude! yet still disregarded and closed-as-stale)
comments [1] on wix/react-native-notifications report that it's a
shame to see a decrease in activity from the maintainers, since it's
the only viable cross-platform library for RN push notifications.

But we don't even use it in a cross-platform way; we uprooted the
last of the linking logic on Android in 01b33ad. It also seems
strange to have two different libraries doing work to support push
notifications on iOS. See also discussion [2].

So, let PushNotificationIOS from react-native take responsibility
for what this library has been doing. Then, since *that's*
deprecated, an upcoming commit will have us using that same code but
from react-native-community, where it's maintained.

These were my steps:

1. Use the setup instructions for our version of
   `react-native-notifications` [3] to tear it down.

2. Use the setup instructions for `PushNotificationIOS` [4] from RN
   v0.60 to complete our setup. Some parts were missing, whether
   because we didn't need that functionality before, or it wasn't
   available in earlier RN versions.

3. Change the bit under the comment "Called when a notification is
   delivered to a foreground app." to correctly call the completion
   handler with UNNotificationPresentationOptions instead of
   UNAuthorizationOptions. N.B.: Also, remove the options that ask
   it to play a sound and show an alert, as these aren't part of the
   current behavior. That just leaves updating the badge count.

4. Make tiny, NFC adjustments, mostly to indentation, to smooth the
   transition to the react-native-community module.

5. Change the call sites to use PushNotificationIOS, and update some
   types and comments. One part that stands out is the removal of
   the "consumeBackgroundQueue" hack from c0e2233. Nothing further
   is necessary, it just works. :)

6. Do various housekeeping things like removing the libdef.

7. On iOS, test that notifications still appear in the closed and
   background states and that, from either state, they navigate to
   the corresponding narrow. All works as expected, with one
   "gotcha": from a cold start, in debug mode, sometimes
   notifications don't navigate. There's an open issue for this [5],
   and it seems it doesn't affect release builds. In debug mode, I
   was able to solve it by disabling "Debug JS Remotely", following
   one comment there. In any case, `getInitialNotification` is what
   we've already been using PushNotificationIOS for, for a long
   time, so this hiccup is not new.

8. On Android, test that notifications appear (regardless of
   closed/background/foreground state) and navigate to the
   corresponding narrow.

[1]: wix/react-native-notifications#519 (comment)
[2]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.20push.20notifications/near/825122
[3]: https://github.com/wix/react-native-notifications/blob/882775fb5/docs/installation.md
[4]: https://reactnative.dev/docs/0.60/pushnotificationios
[5]: react-native-push-notification/ios#24 (comment)
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Nov 10, 2020
Some (rather rude! yet still disregarded and closed-as-stale)
comments [1] on wix/react-native-notifications report that it's a
shame to see a decrease in activity from the maintainers, since it's
the only viable cross-platform library for RN push notifications.

But we don't even use it in a cross-platform way; we uprooted the
last of the linking logic on Android in 01b33ad. It also seems
strange to have two different libraries doing work to support push
notifications on iOS. See also discussion [2].

So, let PushNotificationIOS from react-native take responsibility
for what this library has been doing. Then, since *that's*
deprecated, an upcoming commit will have us using that same code but
from react-native-community, where it's maintained.

These were my steps:

1. Use the setup instructions for our version of
   `react-native-notifications` [3] to tear it down.

2. Use the setup instructions for `PushNotificationIOS` [4] from RN
   v0.60 to complete our setup. Some parts were missing, whether
   because we didn't need that functionality before, or it wasn't
   available in earlier RN versions.

3. Change the bit under the comment "Called when a notification is
   delivered to a foreground app." to correctly call the completion
   handler with UNNotificationPresentationOptions instead of
   UNAuthorizationOptions. N.B.: Also, remove the options that ask
   it to play a sound and show an alert, as these aren't part of the
   current behavior. That just leaves updating the badge count.

4. Make tiny, NFC adjustments, mostly to indentation, to smooth the
   transition to the react-native-community module.

5. Change the call sites to use PushNotificationIOS, and update some
   types and comments. One part that stands out is the removal of
   the "consumeBackgroundQueue" hack from c0e2233. Nothing further
   is necessary, it just works. :)

6. Do various housekeeping things like removing the libdef.

7. On iOS, test that notifications still appear in the closed and
   background states and that, from either state, they navigate to
   the corresponding narrow. All works as expected, with one
   "gotcha": from a cold start, in debug mode, sometimes
   notifications don't navigate. There's an open issue for this [5],
   and it seems it doesn't affect release builds. In debug mode, I
   was able to solve it by disabling "Debug JS Remotely", following
   one comment there. In any case, `getInitialNotification` is what
   we've already been using PushNotificationIOS for, for a long
   time, so this hiccup is not new.

8. On Android, test that notifications appear (regardless of
   closed/background/foreground state) and navigate to the
   corresponding narrow.

[1]: wix/react-native-notifications#519 (comment)
[2]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.20push.20notifications/near/825122
[3]: https://github.com/wix/react-native-notifications/blob/882775fb5/docs/installation.md
[4]: https://reactnative.dev/docs/0.60/pushnotificationios
[5]: react-native-push-notification/ios#24 (comment)
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Dec 2, 2020
wix/react-native-notifications doesn't seem to be maintained [1].
expo-notifications also works on both platforms, but we've decided
it's not for us [2].

But we don't even use react-native-notifications in a cross-platform
way; we uprooted the last of the linking logic on Android in
01b33ad. It also seems non-optimal to have two different libraries
doing work to support push notifications on iOS. See also
discussion [3].

So, let PushNotificationIOS from react-native take responsibility
for what this library has been doing. Then, since *that's*
deprecated, an upcoming commit will have us using that same code but
from react-native-community, where it's maintained.

These were my steps:

1. Use the setup instructions for our version of
   wix/react-native-notifications [4] to tear it down.

2. Use the setup instructions for `PushNotificationIOS` [5] from RN
   v0.62 to complete our setup. We hadn't yet done everything in
   these instructions, whether because we didn't need that
   functionality before, or it wasn't available in earlier RN
   versions. We did some of this setup in the previous commit.

3. Make tiny, NFC adjustments, mostly to indentation, to smooth the
   transition to the react-native-community module.

4. Change the call sites to use PushNotificationIOS, and update some
   types and comments. One part that stands out is the removal of
   the "consumeBackgroundQueue" hack from c0e2233. Nothing further
   is necessary, it just works. :)

5. Do various housekeeping things like removing the libdef.

6. On iOS, test that notifications still appear in the closed and
   background states and that, from either state, they navigate to
   the corresponding narrow. All works as expected, with one
   "gotcha": from a cold start, in debug mode, sometimes
   notifications don't navigate. There's an open issue for this [6],
   and it seems it doesn't affect release builds. In debug mode, I
   was able to solve it by disabling "Debug JS Remotely", following
   one comment there. In any case, `getInitialNotification` is what
   we've already been using PushNotificationIOS for, for a long
   time, so this hiccup is not new.

7. On Android, test that notifications appear (regardless of
   closed/background/foreground state) and that they navigate to the
   corresponding narrow.

[1]: wix/react-native-notifications#519 (comment)
[2]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.20push.20notifications/near/1061130
[3]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.20push.20notifications/near/825122
[4]: https://github.com/wix/react-native-notifications/blob/882775fb5/docs/installation.md
[5]: https://reactnative.dev/docs/0.62/pushnotificationios
[6]: react-native-push-notification/ios#24 (comment)
@borg
Copy link

borg commented Feb 4, 2021

Ran into this issue as well. Basically the initial notifications don't seem to be part of the normal flow, but need to be processed in the initial launch method. With this hack I am adding a delay, and firing off the initial notification (including a fake completion method), which should fit into the normal notification listener pattern. Hopefully this works until there's an official fix.


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

/*
Usual setup for notifications as per docs
*/

  if (launchOptions) { 
      NSDictionary *notification = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
      NSString *const RCTRemoteNotificationReceived = @"RemoteNotificationReceived";
    
       if (notification) {
         double delayInSeconds = 5.0;//waiting for debug load to finish...this is a guess
         
         dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
         dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
           NSLog(@"Initial notification %@",notification);
           
           NSDictionary *userInfo = @{@"notification": notification, @"completionHandler": ^(){}};
           [[NSNotificationCenter defaultCenter] postNotificationName:RCTRemoteNotificationReceived
                                                               object:self
                                                             userInfo:userInfo];
         });
        
       }
   }

      return YES;
}

@pratt3351
Copy link

I've find sometihng.

when i create notification, by localNotificationSchedule or localNotification.
i've set userInfo object variable to null.
like this. PushNotification.localNotificationSchedule({ userInfo:{data:null, text:123} })
and it comes notification at app startup. but has no data in popInitialNotification function.

i've created notification with userInfo object variable to not null.
like this PushNotification.localNotificationSchedule({ userInfo:{text:123} })

it comes data in popInitialNotification function!

chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Feb 8, 2021
wix/react-native-notifications doesn't seem to be maintained [1].
expo-notifications also works on both platforms, but we've decided
it's not for us [2].

But we don't even use react-native-notifications in a cross-platform
way; we uprooted the last of the linking logic on Android in
01b33ad. It also seems non-optimal to have two different libraries
doing work to support push notifications on iOS. See also
discussion [3].

So, let PushNotificationIOS from react-native take responsibility
for what this library has been doing. Then, since *that's*
deprecated, an upcoming commit will have us using that same code but
from react-native-community, where it's maintained.

These were my steps:

1. Use the setup instructions for our version of
   wix/react-native-notifications [4] to tear it down.

2. Use the setup instructions for `PushNotificationIOS` [5] from RN
   v0.62 to complete our setup. We hadn't yet done everything in
   these instructions, whether because we didn't need that
   functionality before, or it wasn't available in earlier RN
   versions. We did some of this setup in the previous commit.

3. Make tiny, NFC adjustments, mostly to indentation, to smooth the
   transition to the react-native-community module.

4. Change the call sites to use PushNotificationIOS, and update some
   types and comments. One part that stands out is the removal of
   the "consumeBackgroundQueue" hack from c0e2233. Nothing further
   is necessary, it just works. :)

5. Do various housekeeping things like removing the libdef.

6. On iOS, test that notifications still appear in the closed and
   background states and that, from either state, they navigate to
   the corresponding narrow. All works as expected, with one
   "gotcha": from a cold start, in debug mode, sometimes
   notifications don't navigate. There's an open issue for this [6],
   and it seems it doesn't affect release builds. In debug mode, I
   was able to solve it by disabling "Debug JS Remotely", following
   one comment there. In any case, `getInitialNotification` is what
   we've already been using PushNotificationIOS for, for a long
   time, so this hiccup is not new.

7. On Android, test that notifications appear (regardless of
   closed/background/foreground state) and that they navigate to the
   corresponding narrow.

[1]: wix/react-native-notifications#519 (comment)
[2]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.20push.20notifications/near/1061130
[3]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.20push.20notifications/near/825122
[4]: https://github.com/wix/react-native-notifications/blob/882775fb5/docs/installation.md
[5]: https://reactnative.dev/docs/0.62/pushnotificationios
[6]: react-native-push-notification/ios#24 (comment)
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue May 10, 2021
wix/react-native-notifications doesn't seem to be maintained [1].
expo-notifications also works on both platforms, but we've decided
it's not for us [2].

But we don't even use react-native-notifications in a cross-platform
way; we uprooted the last of the linking logic on Android in
01b33ad. It also seems non-optimal to have two different libraries
doing work to support push notifications on iOS. See also
discussion [3].

So, let PushNotificationIOS from react-native take responsibility
for what this library has been doing. Then, since *that's*
deprecated, an upcoming commit will have us using that same code but
from react-native-community, where it's maintained.

These were my steps:

1. Use the setup instructions for our version of
   wix/react-native-notifications [4] to tear it down.

2. Use the setup instructions for `PushNotificationIOS` [5] from RN
   v0.62 to complete our setup. We hadn't yet done everything in
   these instructions, whether because we didn't need that
   functionality before, or it wasn't available in earlier RN
   versions. We did some of this setup in the previous commit.

3. Make tiny, NFC adjustments, mostly to indentation, to smooth the
   transition to the react-native-community module.

4. Change the call sites to use PushNotificationIOS, and update some
   types and comments. One part that stands out is the removal of
   the "consumeBackgroundQueue" hack from c0e2233. Nothing further
   is necessary, it just works. :)

5. Do various housekeeping things like removing the libdef.

6. On iOS, test that notifications still appear in the closed and
   background states and that, from either state, they navigate to
   the corresponding narrow. All works as expected, with one
   "gotcha": from a cold start, in debug mode, sometimes
   notifications don't navigate. There's an open issue for this [6],
   and it seems it doesn't affect release builds. In debug mode, I
   was able to solve it by disabling "Debug JS Remotely", following
   one comment there. In any case, `getInitialNotification` is what
   we've already been using PushNotificationIOS for, for a long
   time, so this hiccup is not new.

7. On Android, test that notifications appear (regardless of
   closed/background/foreground state) and that they navigate to the
   corresponding narrow.

[1]: wix/react-native-notifications#519 (comment)
[2]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.20push.20notifications/near/1061130
[3]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.20push.20notifications/near/825122
[4]: https://github.com/wix/react-native-notifications/blob/882775fb5/docs/installation.md
[5]: https://reactnative.dev/docs/0.62/pushnotificationios
[6]: react-native-push-notification/ios#24 (comment)
@Omerdogan3
Copy link

On your xcode
Product -> scheme -> edit scheme
Change your build configuration to release instead of debug.
It works.

chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Jun 17, 2021
wix/react-native-notifications doesn't seem to be maintained [1].
expo-notifications also works on both platforms, but we've decided
it's not for us [2].

But we don't even use react-native-notifications in a cross-platform
way; we uprooted the last of the linking logic on Android in
01b33ad. It also seems non-optimal to have two different libraries
doing work to support push notifications on iOS. See also
discussion [3].

So, let PushNotificationIOS from react-native take responsibility
for what this library has been doing. Then, since *that's*
deprecated, an upcoming commit will have us using that same code but
from react-native-community, where it's maintained.

These were my steps:

1. Use the setup instructions for our version of
   wix/react-native-notifications [4] to tear it down.

2. Use the setup instructions for `PushNotificationIOS` [5] from RN
   v0.62 to complete our setup. We hadn't yet done everything in
   these instructions, whether because we didn't need that
   functionality before, or it wasn't available in earlier RN
   versions. We did some of this setup in the previous commit.

3. Make tiny, NFC adjustments, mostly to indentation, to smooth the
   transition to the react-native-community module.

4. Change the call sites to use PushNotificationIOS, and update some
   types and comments. One part that stands out is the removal of
   the "consumeBackgroundQueue" hack from c0e2233. Nothing further
   is necessary, it just works. :)

5. Do various housekeeping things like removing the libdef.

6. On iOS, test that notifications still appear in the closed and
   background states and that, from either state, they navigate to
   the corresponding narrow. All works as expected, with one
   "gotcha": from a cold start, in debug mode, sometimes
   notifications don't navigate. There's an open issue for this [6],
   and it seems it doesn't affect release builds. In debug mode, I
   was able to solve it by disabling "Debug JS Remotely", following
   one comment there. In any case, `getInitialNotification` is what
   we've already been using PushNotificationIOS for, for a long
   time, so this hiccup is not new.

7. On Android, test that notifications appear (regardless of
   closed/background/foreground state) and that they navigate to the
   corresponding narrow.

[1]: wix/react-native-notifications#519 (comment)
[2]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.20push.20notifications/near/1061130
[3]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.20push.20notifications/near/825122
[4]: https://github.com/wix/react-native-notifications/blob/882775fb5/docs/installation.md
[5]: https://reactnative.dev/docs/0.62/pushnotificationios
[6]: react-native-push-notification/ios#24 (comment)
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Jun 18, 2021
wix/react-native-notifications doesn't seem to be maintained [1].
expo-notifications also works on both platforms, but we've decided
it's not for us [2].

But we don't even use react-native-notifications in a cross-platform
way; we uprooted the last of the linking logic on Android in
01b33ad. It also seems non-optimal to have two different libraries
doing work to support push notifications on iOS. See also
discussion [3].

So, let PushNotificationIOS from react-native take responsibility
for what this library has been doing. Then, since *that's*
deprecated, an upcoming commit will have us using that same code but
from react-native-community, where it's maintained.

These were my steps:

1. Use the setup instructions for our version of
   wix/react-native-notifications [4] to tear it down.

2. Use the setup instructions for `PushNotificationIOS` [5] from RN
   v0.62 to complete our setup. We hadn't yet done everything in
   these instructions, whether because we didn't need that
   functionality before, or it wasn't available in earlier RN
   versions. We did some of this setup in the previous commit.

3. Make tiny, NFC adjustments, mostly to indentation, to smooth the
   transition to the react-native-community module.

4. Change the call sites to use PushNotificationIOS, and update some
   types and comments. One part that stands out is the removal of
   the "consumeBackgroundQueue" hack from c0e2233. Nothing further
   is necessary, it just works. :)

5. Do various housekeeping things like removing the libdef.

6. On iOS, test that notifications still appear in the closed and
   background states and that, from either state, they navigate to
   the corresponding narrow. All works as expected, with one
   "gotcha": from a cold start, in debug mode, sometimes
   notifications don't navigate. There's an open issue for this [6],
   and it seems it doesn't affect release builds. In debug mode, I
   was able to solve it by disabling "Debug JS Remotely", following
   one comment there. In any case, `getInitialNotification` is what
   we've already been using PushNotificationIOS for, for a long
   time, so this hiccup is not new.

7. On Android, test that notifications appear (regardless of
   closed/background/foreground state) and that they navigate to the
   corresponding narrow.

[1]: wix/react-native-notifications#519 (comment)
[2]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.20push.20notifications/near/1061130
[3]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.20push.20notifications/near/825122
[4]: https://github.com/wix/react-native-notifications/blob/882775fb5/docs/installation.md
[5]: https://reactnative.dev/docs/0.62/pushnotificationios
[6]: react-native-push-notification/ios#24 (comment)
@anishtr4
Copy link

anishtr4 commented Jun 18, 2021

Does any one have a working GitHub repo . I tried almost all the above fixed none of them didn’t worked . I have tried in release mode also still getinitialnotification always return null. This happens for localnotification and remotenotification

@anishtr4
Copy link

On your xcode
Product -> scheme -> edit scheme
Change your build configuration to release instead of debug.
It works.

Did you have any working example for this even in release mode also its returning null alwasy.

@anishtr4
Copy link

anishtr4 commented Aug 17, 2021

I still could't get this fixed. Can some one look into my test project repo and help me to identify the issue.

https://github.com/anishtr4/salesforce_react_pushnotitifcation.git

@vvdodiya
Copy link

@anishtr4 I have find something
I have added following line in didFinishLaunchingWithOptions method in appdelegate.m file

[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self]; // add this line

so finally it will look like :

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    ...
    // Define UNUserNotificationCenter

    [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self]; // add this line

    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;

    return YES;
    }

It will work for me

@sahil2401
Copy link

sahil2401 commented Nov 11, 2024

This works for me

 const handleNotificationOpenedApp = () => {
        messaging().onNotificationOpenedApp((remoteMessage) => {
          console.log("Notification opened from background:", remoteMessage);
          return remoteMessage
        });
      };

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