[Proposal] Enhance Linking API for File-Based App Launches on iOS
douglasjunior opened this issue · 0 comments
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:
- https://forums.developer.apple.com/forums/thread/47890
- https://forums.developer.apple.com/forums/thread/697041
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:
- 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 the app is launched from a file selection, the file URL is received in the
-
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.
- The URL is received again in the
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 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.