@@ -12,11 +12,15 @@ import kotlinx.cinterop.useContents
12
12
import kotlinx.coroutines.CoroutineScope
13
13
import platform.Foundation.HTTPBody
14
14
import platform.Foundation.HTTPMethod
15
+ import platform.Foundation.NSArray
15
16
import platform.Foundation.NSBundle
16
17
import platform.Foundation.NSData
18
+ import platform.Foundation.NSDocumentDirectory
17
19
import platform.Foundation.NSMutableURLRequest
20
+ import platform.Foundation.NSSearchPathForDirectoriesInDomains
18
21
import platform.Foundation.NSString
19
22
import platform.Foundation.NSURL
23
+ import platform.Foundation.NSUserDomainMask
20
24
import platform.Foundation.create
21
25
import platform.Foundation.setValue
22
26
import platform.Foundation.stringByDeletingLastPathComponent
@@ -50,6 +54,33 @@ class IOSWebView(
50
54
url : String ,
51
55
additionalHttpHeaders : Map <String , String >,
52
56
) {
57
+ // Check if it's a file URL
58
+ if (url.startsWith(" file://" )) {
59
+ val fileURL = NSURL (string = url)
60
+ if (fileURL != null && fileURL.isFileURL()) {
61
+ // Use document directory for read access to fix real device issues
62
+ val documentPaths =
63
+ NSSearchPathForDirectoriesInDomains (
64
+ NSDocumentDirectory ,
65
+ NSUserDomainMask ,
66
+ true ,
67
+ ) as NSArray
68
+ val readAccessURL =
69
+ if (documentPaths.count > 0u ) {
70
+ val documentPath = documentPaths.objectAtIndex(0u ) as ? String
71
+ documentPath?.let { NSURL .fileURLWithPath(it) }
72
+ } else {
73
+ null
74
+ }
75
+
76
+ if (readAccessURL != null ) {
77
+ webView.loadFileURL(fileURL, readAccessURL)
78
+ return
79
+ }
80
+ }
81
+ }
82
+
83
+ // Handle regular HTTP/HTTPS URLs
53
84
val request =
54
85
NSMutableURLRequest .requestWithURL(
55
86
URL = NSURL (string = url),
0 commit comments