-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Fix IOSStorageFolder permission problem #13976
Conversation
@dotnet-policy-service agree |
You can test this PR using the following package version. |
This commit fixes "Operation not permitted" errors when accessing folders opened via StorageProvider.OpenFolderPickerAsync by calling [Start/Stop]AccessingSecurityScopedResource on IOSStorageFolder's Url.
c87fa1f
to
6752255
Compare
Wrap individual operations in [Start/Stop]AccessingSecurityScopedResource calls instead of retaining access for the whole lifetime of the folder.
You can test this PR using the following package version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This contains the IOSStorageFolder permission fixes: AvaloniaUI/Avalonia#13976
* Fix IOSStorageFolder permission problem This commit fixes "Operation not permitted" errors when accessing folders opened via StorageProvider.OpenFolderPickerAsync by calling [Start/Stop]AccessingSecurityScopedResource on IOSStorageFolder's Url. * Narrow down security scoped resource access scope Wrap individual operations in [Start/Stop]AccessingSecurityScopedResource calls instead of retaining access for the whole lifetime of the folder. #Conflicts: # src/iOS/Avalonia.iOS/Storage/IOSStorageItem.cs
What does the pull request do?
This PR aims to fix
StorageProvider.OpenFolderPickerAsync
permission errors when run on an iOS device.What is the current behavior?
Folders opened using
StorageProvider.OpenFolderPickerAsync
can't be used on an iPhone, because of "Operation not permitted" errors on every operation.Please note that these errors occur only on a real device, the emulator works without the changes in this PR. My test device runs iOS 17.1.2, and I do not have access to any other Apple devices / iOS versions to test on.
I have attached a minimal test application to demonstrate this behavior. The application asks the user for a folder, and puts the name of all files and folders under it into a
ListBox
. The file/folder list will appear in theListBox
when run in the emulator, but not when run on a real device.What is the updated/expected behavior with this PR?
With the commit in this PR, folders opened using
StorageProvider.OpenFolderPickerAsync
can be accessed as normal.How was the solution implemented (if it's not obvious)?
The root cause of the problem is that
IOSStorageFolder
does not callStartAccessingSecurityScopedResource
/StopAccessingSecurityScopedResource
on itsUrl
. This PR adds these calls toIOSStorageFolder
's constructor andDispose
methods, similarly toIOSSecurityScopedStream
.