Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

handleActionWithIdentifier not firing when app is not running (i.e. force-quit). #3

Open
irfaan opened this issue Jan 14, 2016 · 3 comments

Comments

@irfaan
Copy link
Contributor

irfaan commented Jan 14, 2016

handleActionWithIdentifier works perfectly when app is backgrounded, but as soon as the app is killed/force-quit, actions on push notifications go silently, appearing not to trigger [RNNotificationActions application:application handleActionWithIdentifier:identifier forRemoteNotification:userInfo withResponseInfo:responseInfo completionHandler:completionHandler]; at all.

Performing a task within the handleActionWithIdentifier declaration works fine (i.e. not sending a notification over the bridge to react-native).

I have an inkling that it might be related to done() (i.e. the completionHandler) being called too early and terminating the app before the task/operation can take place (see http://stackoverflow.com/a/29912511/1183749), though I have taken precautions to only call done() after completing my task (write to db). This, obviously, only works when the app is backgrounded and I don't know how else to test whether the completionHandler is being called at the right time and the app is not being terminated prematurely.

FYI: Background Modes for Remote Notifications is enabled in Capabilities.

Any ideas?

irfaan added a commit to irfaan/react-native-ios-notification-actions that referenced this issue Jan 14, 2016
Supports actions for backgrounded app but still suffers from issue of silent actions on force-quitted app (see holmesal#3)
@irfaan irfaan changed the title handleActionWithIdentifier not firing when app is not running (i.e. killed). handleActionWithIdentifier not firing when app is not running (i.e. force-quit). Jan 14, 2016
@holmesal
Copy link
Owner

Just to clarify - is handleActionWithIdentifier being called (breakpoint it) when the app has been killed and notification action is interacted with, or not?

I think you're probably right that the failure is due to the completion handler being called too early - to test, can you try commenting out lines 131 and 136 in RNNotificationActions.m and see if your JS callbacks work when the application has been killed?

Let me know if that fixes it - if so, storing those completion blocks by actionId on the obj-c side should do the trick. My objective-c skills are pretty noob-level, but I can give implementing that a shot.

@irfaan
Copy link
Contributor Author

irfaan commented Jan 15, 2016

  1. - (void)application:(UIApplication *)application handleActionWithIdentifier ... is called for app in 'not-running' state when interacting with notification action.

    For reference, I set a breakpoint for a 'not-running' app using this method:
    Product > Scheme > Edit Scheme > Launch: Wait for executable to be launched
    (h/t http://stackoverflow.com/a/19069234/1183749)

  2. Commenting out completionHandler(); on those lines you mentioned in RNNotificationActions.m oddly causes the following:

    • When backgrounded, interacting with a notification does nothing until the app is manually foregrounded.

    • [RNNotificationActions application:application handleActionWithIdentifier ... is called when the app is in 'not-running' / killed state after interacting with the notification action (setting a breakpoint in similar fashion).

    • The onComplete inside new NotificationActions.Action does not appear to be called.

      Tested by selecting `Automatically continue after evaluating actions' for the breakpoint and writing to the console inside the onComplete block. Nothing prints to the console.

Haven't tested, but could this be related? facebook/react-native#1282 (even though I'm using RN 0.18.0-rc and this seems to have been resolved in 0.14)?

@maxiaodong97
Copy link

Hi, holmesal ,
First, thanks for all the work you did. I fixed this issue here if you want to merge.
https://github.com/maxiaodong97/react-native-ios-notification-actions

There is still a minor issue that can not be easy fix: as the app is not running in the forground, the component may not be mounted. So the NotifcationAction needs to be initialized out side of the component to be able to register the event as soon as the JS get parsed.

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

No branches or pull requests

3 participants