mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 10:29:58 +02:00
Add mobile file access sources
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.vnidrop.app.core
|
||||
|
||||
import platform.Foundation.NSURL
|
||||
import uniffi.vnidrop.SourceKind
|
||||
|
||||
internal actual suspend fun <T> withPlatformPathAccess(
|
||||
kind: SourceKind,
|
||||
value: String,
|
||||
block: suspend () -> T,
|
||||
): T {
|
||||
if (kind != SourceKind.IOS_SECURITY_SCOPED_URL) {
|
||||
return block()
|
||||
}
|
||||
|
||||
val url = NSURL.URLWithString(value) ?: NSURL.fileURLWithPath(value)
|
||||
val didStartAccess = url.startAccessingSecurityScopedResource()
|
||||
return try {
|
||||
block()
|
||||
} finally {
|
||||
if (didStartAccess) {
|
||||
url.stopAccessingSecurityScopedResource()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user