Skip to content

Conversation

@onehumandev
Copy link
Contributor

On iOS, when trying to access a file that exists outside of the app sandbox, one of 2 things need to happen to be able to perform any operations on said file:

  1. A copy of the file needs to be made to the internal app sandbox
  2. The method startAccessingSecurityScopedResource needs to be called.

Previously, a copy of the file was always being made when a file was selected through the picker dialog.

While this did ensure there were no file access exceptions when reading from the file, it does not scale well for large files.

To resolve this, we now support calling startAccessingSecurityScopedResource.

This is called by startFileAccess in the TS API, and when done accessing the file, endFileAccess should be called.

This MR only supports this change for iOS; MacOS has a different set of needs for security scoped resources.

See discussion in #3716 for more discussion of the difference between iOS and MacOS.

@onehumandev onehumandev requested a review from a team as a code owner December 1, 2025 15:32
@onehumandev
Copy link
Contributor Author

c. @velocitysystems Here is the MR for the changes to support startAccessingSecurityScopedResource for working with Cloud providers without requiring making a local copy of the file. Thanks!

@onehumandev onehumandev force-pushed the aldewaal/ios_security_scoping branch from d4c8e4b to 749a149 Compare December 2, 2025 20:00

#[command]
pub(crate) async fn end_file_access<R: Runtime>(
_window: Window<R>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_window is unused here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the window parameter is required for commands to be invoked; is that incorrect?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Tauri's documentation, Window, AppHandle, and State<T> are "Special Parameters" that are automatically injected by the #[tauri::command] macro if present, but they're not required.

Since end_file_access doesn't use the window for anything (no scope management, no parent window needed), it can safely be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I remove the initial argument, we get a compilation error related to where we register the handler:

plugins/dialog/src/commands.rs:427:1
    |
427 |   #[command]
    |   ^^^^^^^^^^ cannot infer type
    |
   ::: plugins/dialog/src/lib.rs:203:25
    |
203 |           .invoke_handler(tauri::generate_handler![
    |  _________________________-
204 | |             commands::open,
205 | |             commands::save,
206 | |             commands::message,
...   |
210 | |             commands::end_file_access,
211 | |         ])
    | |_________- in this macro invocation
    |
    = note: cannot satisfy `_: tauri::Runtime`
note: required by a bound in `end_file_access`
   --> plugins/dialog/src/commands.rs:428:40
    |
428 | pub(crate) async fn end_file_access<R: Runtime>(

We can at least change the argument to an AppHandle instead of a Window, but removing the parameter will cause a compilation error.
Is there something I am missing with this?

@onehumandev onehumandev force-pushed the aldewaal/ios_security_scoping branch 2 times, most recently from fcbcbd9 to 16dea72 Compare December 9, 2025 21:53
andrewdewaal and others added 4 commits December 23, 2025 10:30
…i-apps#3030)

On iOS, when trying to access a file that exists outside of the app
sandbox, one of 2 things need to happen to be able to perform any
operations on said file:
1) A copy of the file needs to be made to the internal app sandbox
2) The method `startAccessingSecurityScopedResource` needs to be called.

Previously, a copy of the file was always being made when a file was
selected through the picker dialog.

While this did ensure there were no file access exceptions when reading
from the file, it does not scale well for large files.

To resolve this, we now support calling `startAccessingSecurityScopedResource`.

This is called by `startFileAccess` in the TS API, and when done accessing the file,
`endFileAccess` should be called.

This MR only supports this change for iOS; MacOS has a different set of needs
for security scoped resources.

See discussion in #3716 for more discussion of the difference between iOS and MacOS.
…ated to scoped security resources.

* Make starting and stopping security scoped access thread safe.
* Create enum describing result of stopping file access to describe if no resource was found to release.
* Make startFileAccess errors more descriptive based on actual issue.
* Update sample dialog page to actually print the text.
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

Successfully merging this pull request may close these issues.

3 participants