Skip to content

Commit

Permalink
Properly access security scoped resource in IOSFileManager
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
msasikanth committed Oct 29, 2023
1 parent bc2cd17 commit 4d27622
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4d27622

Please sign in to comment.