Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Enhance Linking API for File-Based App Launches on iOS #788

Open
douglasjunior opened this issue May 23, 2024 · 0 comments
Open

Comments

@douglasjunior
Copy link

douglasjunior commented 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:

  1. 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.
  2. 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.

@douglasjunior 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant