From 4d276220636cf1f06e36d63a933bce677698d6e0 Mon Sep 17 00:00:00 2001 From: Sasikanth Miriyampalli Date: Sun, 29 Oct 2023 15:30:14 +0530 Subject: [PATCH] Properly access security scoped resource in `IOSFileManager` Since the URLs we receive from document picker are security scoped, we need to call `startAccessingSecurityScopeResource` and once the action is done we release it by calling `stopAccessingSecurityScopedResource` --- .../rss/reader/filemanager/IOSFileManager.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/shared/src/iosMain/kotlin/dev/sasikanth/rss/reader/filemanager/IOSFileManager.kt b/shared/src/iosMain/kotlin/dev/sasikanth/rss/reader/filemanager/IOSFileManager.kt index 6d5f18345..01f6bcde6 100644 --- a/shared/src/iosMain/kotlin/dev/sasikanth/rss/reader/filemanager/IOSFileManager.kt +++ b/shared/src/iosMain/kotlin/dev/sasikanth/rss/reader/filemanager/IOSFileManager.kt @@ -114,7 +114,17 @@ private class DocumentPickerDelegate( controller: UIDocumentPickerViewController, didPickDocumentAtURL: NSURL ) { - didPickDocument(didPickDocumentAtURL) + try { + val scoped = didPickDocumentAtURL.startAccessingSecurityScopedResource() + if (scoped) { + didPickDocument(didPickDocumentAtURL) + } + } catch (e: Exception) { + cancelledDocumentPicker() + throw e + } finally { + didPickDocumentAtURL.stopAccessingSecurityScopedResource() + } } override fun documentPickerWasCancelled(controller: UIDocumentPickerViewController) {