When opening my app in simulator via a deeplink, url event never fires.
Note that getInitialurl
works if app was closed.
But if app is already open and I run npx uri-scheme open "mychat://bar" --ios
, app focuses but no url event fires…
Anyone had this problem ?
I’m running XCode 13.4.1
MacOS 12.5.1
React Native 0.70
2
Answers
The event needs some additional configuration within your AppDelegate.m file in order to emit the events as mentioned in the docs. Either open your Project from XCode and edit AppDelegate.m or open ./ios/{YOUR_PROJECT_NAME}/AppDelegate.m (or AppDelegate.mm) file and add the following lines at the end of the file before the @end tag comes:
Important: If you get this working, you have two ways of handling the deeplink event and you have to handle them seperately! I think the second one will help you to solve your problem.
1 – The app is closed and will open by the deeplink:
2 – The app is already running and will be focused using deeplink:
Putting these lines within your apps view and assumed your app has some sort of state (e.g. using the useState hook or redux) it’ll called on every state change that occurs, due to everything beside the state itself will be re-rendered on changing the state. Therefore I would suggest you to call these two methods only one time when app is starting and you can accomplish that by doing so:
I hope this will help you to solve your problem.
In my case, I was adding the required code block of AppDelegate below @interface AppDelegate, but have to add inside @implementation AppDelegate which below interface.