You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm encountering an issue with the Linking.getInitialURL API in React Native related to app initialization from file selections. The problem arises due to permission restrictions when accessing a file used to start the app. This is specific to iOS, where there's a notable difference in how URLs are handled when the app is launched via file selection.
Currently, the Linking.getInitialURL API is designed primarily for handling Deep Links (Universal Links). However, when dealing with files, there are specific nuances, particularly on iOS:
During App Launch:
When the app is launched from a file selection, the file URL is received in the AppDelegate.mm file within the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions event.
At this point, the received URL is the original file path, which the app does not have permission to access.
React Native stores this inaccessible URL and returns it via Linking.getInitialURL, causing issues.
When App is Already Open:
The URL is received again in the - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options event.
Here, the URL is a temporary path that the app does have permission to access.
Currently, React Native only handles this URL via Linking.addEventListener, which works when the app is already running but not during initial launch.
Proposed Solution
To address this issue, I propose the following enhancement to the Linking.getInitialURL API:
During app initialization, ignore the URL received in the didFinishLaunchingWithOptions event.
Store the accessible temporary URL received in the openURL event in a static variable.
Modify Linking.getInitialURL to return the URL stored from the openURL event, ensuring it is accessible and valid.
Discussion points
This enhancement will ensure that developers can reliably use Linking.getInitialURL to access files used to launch the app, improving the developer experience and functionality of React Native apps that rely on file-based interactions.
The text was updated successfully, but these errors were encountered:
douglasjunior
changed the title
[Proposal] Enhance Linking API for File-Based App Launches
[Proposal] Enhance Linking API for File-Based App Launches on iOS
May 23, 2024
Introduction
I'm encountering an issue with the
Linking.getInitialURL
API in React Native related to app initialization from file selections. The problem arises due to permission restrictions when accessing a file used to start the app. This is specific to iOS, where there's a notable difference in how URLs are handled when the app is launched via file selection.Sources:
Details
Currently, the
Linking.getInitialURL
API is designed primarily for handling Deep Links (Universal Links). However, when dealing with files, there are specific nuances, particularly on iOS:During App Launch:
AppDelegate.mm
file within the- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
event.Linking.getInitialURL
, causing issues.When App is Already Open:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
event.Linking.addEventListener
, which works when the app is already running but not during initial launch.Proposed Solution
To address this issue, I propose the following enhancement to the
Linking.getInitialURL
API:didFinishLaunchingWithOptions
event.openURL
event in a static variable.Linking.getInitialURL
to return the URL stored from theopenURL
event, ensuring it is accessible and valid.Discussion points
This enhancement will ensure that developers can reliably use
Linking.getInitialURL
to access files used to launch the app, improving the developer experience and functionality of React Native apps that rely on file-based interactions.The text was updated successfully, but these errors were encountered: