jordanbyron / react-native-quick-actions

A react-native interface for Touch 3D home screen quick actions
MIT License
1.06k stars 93 forks source link

iOS - Item press not working when app is in background #96

Open aaguiar66934 opened 4 years ago

aaguiar66934 commented 4 years ago

In iOS (tested in 13.3.1) when the app is in background, the item press is not working. It seems that the event "quickActionShortcut" is never triggered. My react-native code is as you recommend in the documentation:

DeviceEventEmitter.addListener("quickActionShortcut", data => {
  console.log(data);
});

"react": "16.9.0", "react-native": "0.61.2", "react-native-quick-actions": "0.3.13"

joaodematejr commented 4 years ago

+1

GodsEye-07 commented 4 years ago

Same in Android as well.

shukerullah commented 4 years ago

For me listener was working fine but it was triggered before navigator was initialized. I added setTimeout as you can see in following snippet:

function quickAction(data) {
  if (data && data.userInfo && data.userInfo.url) {
    setTimeout(() => {
      LinkRoutes(data.userInfo.url);
    }, TIME);
  }
}
pmcamacho commented 1 year ago

Hey! All good?

Indeed. I was trying this library and this also does not work on ios when the app is in background for me. Does anyone found a workaround? Are there plans to make it work?

The following callback does not get triggered when ios app is on background DeviceEventEmitter.addListener("quickActionShortcut", data => { console.log(data); });

I am using: "react": "18.1.0", "react-native": "0.70.1", "react-native-quick-actions": "^0.3.13",

and tested it in simulator and iphone 13 with ios 15 and 16.

Thanks in advance!

pmcamacho commented 1 year ago

I figured out the problem I was having! It works now also for ios both closed or in background app state.

So in the AppDelegate.m file you need to add as stated in the docs #import "RNQuickActionManager.h" and also - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded)) completionHandler { [RNQuickActionManager onQuickActionPress:shortcutItem completionHandler:completionHandler]; }

But careful do not put the import or the code inside an @ if (with no space between @ and if) in the code.

So in my case the code I added it right before the last @ end (with no space between @ and end) and the import right on top near the other ones.

So basically I was adding them inside @ if (with no space between @ and if) and so I guess the code was not loaded and run in my case so I was not able to make it work and it was failing silently.

Hope it helps someone!

Happy coding!