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 Action not firing properly when the app is not active

See original GitHub issue

Question

In iOS, tapping on an action in a notification (Yes/No in my case) does not work while the app is not active. If the app is in the background or it is in the foreground everything works as expected. I believe this is an issue with https://github.com/react-native-community/push-notification-ios, so I also have an issue open on that repo https://github.com/react-native-community/push-notification-ios/issues/178.

One important observation I’ve noticed is that PushNotification.popInitialNotification does not get invoked at all. I believe this is because of the fact that PushNotificationIOS.getInitialNotification() resolves to null as noted in my issue on that repo.

I do have a workaround for this, which is to fire an event over the event emitter, but I do not like my custom solution.

Has anyone ran into this? Is this a bug to be fixed in https://github.com/react-native-community/push-notification-ios? Thanks in advance for your responses.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
Dallas62commented, Sep 15, 2020

Since I’m not the maintainer of the iOS library, I can’t answer to this question. But I think the main reason is time 😅

0reactions
ForamPatthacommented, Jan 21, 2021

@ForamPattha of course!

The trick is to utilize React Native’s Event Emitter to bypass this defect.

Somewhere in your swift code, likely inside of userNotificationCenter(UNUserNotificationCenter, UNUserNotificationResponse, Void) you need to add EventEmitter.instance.dispatch(event: {your event})

In the JS layer, we need to listen for this event. React Native provides a JS interface for this. It’s kind of hidden in the docs so stackoverflow might be your best bet at getting other examples/help. Refer the JS below:

import { NativeEventEmitter } from 'react-native';
const { ReactNativeEventEmitter } = NativeModules;
const reactNativeEventEmitter = new NativeEventEmitter(ReactNativeEventEmitter);
// ...
let myListener = reactNativeEventEmitter.addListener(
  'yourEventString',
  data => {
    // your callback
  },
);

Make sure to remove the event listener when the component is destroyed to avoid memory leaks:

  componentWillUnmount(){
    myListener.remove();
  }

Let me know how it goes!

Can you please describe in details I’m not understand your point . Or if possible can you please share your code or send screen shot of your code file ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

my app not working after few days … | Apple Developer Forums
I'am new to IOS development i had developed a program which is still not published in appstore but i'm using it by directly...
Read more >
ios - Push notifications not working properly when the app is ...
Push notifications not working properly when the app is not active (killed) ... I'm facing a problem with push notifications, I'm using Google ......
Read more >
12 Best Tips to Fix Live Activities Not Working in iOS 16 on ...
Here are the 12 best tips and tricks to fix Live Activities not working on iPhone Lock Screen in iOS 16 or later....
Read more >
Common issues and resolutions for Power Apps
If you're running into issues using Power Apps, try these common ... Images added from iOS do not contain meta-data information (January 20, ......
Read more >
Focus Not Working on your iPhone? 10 Ways to Fix the Issue
If an app can bypass your focus mode then you should go ahead and check if the app hasn't been whitelisted by you...
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