ReactNative: Does `Linking.addEventListener` fire when the app is running background?(Deep linking) - react-native

When I set up like this
https://facebook.github.io/react-native/docs/linking#basic-usage
and open the app via Custom URL Scheme,
_handleOpenURL catches the URL if the app is shutdown, but doesn't if the app is running background.(iOS)
So can't I use the Linking.addEventListener when the app is already running?

I was having this issue working on a detached Expo project because I had added the suggested code from https://facebook.github.io/react-native/docs/linking.html to the *AppDelegate.m but Expo already provides slightly different functions for handling URL events. Removing the code from the React Native docs made it work for me.

Related

How to run a JS funktion before Metro replaces my React Native JS code via "Reload"

I am writing a React Native app with hardware access. This means that I setup the hardware at application startup. Then I could click "Reload" in the developer menu. But before the code is reloaded I need to tear down my hardware setup since otherwise the setup during restart fails.
Is there any way I can create some kind of callback function/hook that allows me to get informed immediately before app reload? Than I could to the tear down in this function. Please note the code has to run in the handy app (not as a kind of plugin for metro bundler).

How to open Deep Link in Expo Dev Client

I recently added the dev-client in my Expo (Bare Workflow) React Native App. The deep linking configuration was working fine earlier with my scheme as:
scheme://mobile-prefix/product/10
In the local environment, I tried using the local development Deep-link as follows:
scheme://expo-development-client/?url=http://192.168.5.80:8081
This opened the app ^. This was according to the documentation: https://docs.expo.dev/development/development-workflows/#deep-linking-urls
But it still isn't clear how do I open the deep link say to a particular product which was earlier: mobile-prefix/product/10.
The way to make it work was:
Create development build.
Then use the local scheme URI, like below. See screenshot for reference
scheme://192.168.5.80:8081/mobile-prefix/product/10
So the above URI works ^
where mobile-prefix/product/10 is the one configured on React Native App itself.
I was using your above answer with React Navigation which didn't work.
You might not need the IP address. Just your-scheme-here://mobile-prefix/product/10 will work.

modifying a bundled react native app using expo

I have created a react native using app and created an apk for that using expo. Now I have to make some modification in that app. So do I need to build that again using build:android? or Is there any method to modify content in bundled app
If you have the over-the-air updates that expo offers enabled (I believe it's enabled by default), then whenever you publish your app (expo publish), the app on your phone will update automatically (you don't need to download the new apk). That also works when the app is on Play Store.
The way this works, is basically the app requests an updated js file from a public url on launch and runs that js instead of the old one. I personally dislike this approach so I disabled OTA updates for my app. In case you do too, then, you either need to manually listen for updates in your app (please refer to the above link) or install the new apk every time you build a new version (this is only useful in development).

React Native Firebase: Check if module installed

Is there any way I can pre-check if the module, example notification, is configured in Native side?
For example, I call firebase.notification() it cause app crash. I'd to check before calling the notification() function.
** I am using "react-native-firebase": "^5.5.6";
---- Added -----
I am using codepush to do hot deployment.
The issue is that, my Android app v1.0 doesn't have notification configured in native side (android) namely without new RNFirebaseNotificationsPackage().
The new native update v1.1 I added new RNFirebaseNotificationsPackage() to native code.
By calling firebase.notification(), app v1.0 crashed while v1.1 works.
I understand that checking app version can prevent this issue, but I need a direct solution to make sure RNFirebaseNotificationsPackage is integrated at native side.
I think you should use notificaiton like this:
firebase.notifications()
If you want to pre check if firebase exist, you may do like this:
if (typeof firebase !== 'undefined) {
I was having the same problem you had but in my case it was a difference between Android and iOS versions.
The solution that worked for me was wrapping the firebase call inside a try/catch block to avoid the crash.

How to manage ios background modes via react native (for example calling API while app is killed)

I'm developing a react-native app and I'm facing a problem: I need to execute a periodical task (an API call to post some data) in all possible cases: the app is in the background, app is in foreground and app is killed (double tap on the home button and swipe up).
How could I achieve this in iOS?
For Android, HeadlessJS seems to work fine, but for iOS I couldn't find anything which could fit my case.
I've tried with react-native-background-fetch but if the app is killed, also the background fetch is halted (https://github.com/transistorsoft/react-native-background-fetch/issues/34)
I've tried react-native-background-timer, but it works only until the app is killed.
I've also tried adding a geolocation native library to set background mode "location updates" capability, and calling its start method inside the didFinishLaunchingWithOptions into AppDelegate.m. But also this works only until the app is killed.
If I use the same native library on a native iOS app, and I call it inside the same method into AppDelegate.m, it keeps working also when the app is killed.
So which is the difference between the native and react-native app that lets the app survive the force-quit?
I've also tried reading this https://developer.apple.com/library/archive/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html but I couldn't replicate that info via react-native.
Can someone help me, please?