Browse Source

fix(ios): Make allowFileAccessFromFileURLs work in iOS. (#1061)

StasD 4 years ago
parent
commit
88b64981f4
4 changed files with 17 additions and 7 deletions
  1. 7
    7
      docs/Reference.md
  2. 1
    0
      ios/RNCWebView.h
  3. 8
    0
      ios/RNCWebView.m
  4. 1
    0
      ios/RNCWebViewManager.m

+ 7
- 7
docs/Reference.md View File

@@ -686,11 +686,11 @@ Boolean value to control whether DOM Storage is enabled. Used only in Android.
686 686
 
687 687
 ### `javaScriptEnabled`
688 688
 
689
-Boolean value to enable JavaScript in the `WebView`. Used on Android only as JavaScript is enabled by default on iOS. The default value is `true`.
689
+Boolean value to enable JavaScript in the `WebView`. The default value is `true`.
690 690
 
691
-| Type | Required | Platform |
692
-| ---- | -------- | -------- |
693
-| bool | No       | Android  |
691
+| Type | Required |
692
+| ---- | -------- |
693
+| bool | No       |
694 694
 
695 695
 ---
696 696
 
@@ -914,9 +914,9 @@ Set whether Geolocation is enabled in the `WebView`. The default value is `false
914 914
 
915 915
 Boolean that sets whether JavaScript running in the context of a file scheme URL should be allowed to access content from other file scheme URLs. The default value is `false`.
916 916
 
917
-| Type | Required | Platform |
918
-| ---- | -------- | -------- |
919
-| bool | No       | Android  |
917
+| Type | Required |
918
+| ---- | -------- |
919
+| bool | No       |
920 920
 
921 921
 ---
922 922
 

+ 1
- 0
ios/RNCWebView.h View File

@@ -47,6 +47,7 @@
47 47
 @property (nonatomic, copy) NSString * _Nullable applicationNameForUserAgent;
48 48
 @property (nonatomic, assign) BOOL cacheEnabled;
49 49
 @property (nonatomic, assign) BOOL javaScriptEnabled;
50
+@property (nonatomic, assign) BOOL allowFileAccessFromFileURLs;
50 51
 @property (nonatomic, assign) BOOL allowsLinkPreview;
51 52
 @property (nonatomic, assign) BOOL showsHorizontalScrollIndicator;
52 53
 @property (nonatomic, assign) BOOL showsVerticalScrollIndicator;

+ 8
- 0
ios/RNCWebView.m View File

@@ -138,8 +138,16 @@ static NSDictionary* customCertificatesForHost;
138 138
   if (self.window != nil && _webView == nil) {
139 139
     WKWebViewConfiguration *wkWebViewConfig = [WKWebViewConfiguration new];
140 140
     WKPreferences *prefs = [[WKPreferences alloc]init];
141
+    BOOL _prefsUsed = NO;
141 142
     if (!_javaScriptEnabled) {
142 143
       prefs.javaScriptEnabled = NO;
144
+      _prefsUsed = YES;
145
+    }
146
+    if (_allowFileAccessFromFileURLs) {
147
+      [prefs setValue:@TRUE forKey:@"allowFileAccessFromFileURLs"];
148
+      _prefsUsed = YES;
149
+    }
150
+    if (_prefsUsed) {
143 151
       wkWebViewConfig.preferences = prefs;
144 152
     }
145 153
     if (_incognito) {

+ 1
- 0
ios/RNCWebViewManager.m View File

@@ -53,6 +53,7 @@ RCT_EXPORT_VIEW_PROPERTY(onContentProcessDidTerminate, RCTDirectEventBlock)
53 53
 RCT_EXPORT_VIEW_PROPERTY(injectedJavaScript, NSString)
54 54
 RCT_EXPORT_VIEW_PROPERTY(injectedJavaScriptBeforeContentLoaded, NSString)
55 55
 RCT_EXPORT_VIEW_PROPERTY(javaScriptEnabled, BOOL)
56
+RCT_EXPORT_VIEW_PROPERTY(allowFileAccessFromFileURLs, BOOL)
56 57
 RCT_EXPORT_VIEW_PROPERTY(allowsInlineMediaPlayback, BOOL)
57 58
 RCT_EXPORT_VIEW_PROPERTY(mediaPlaybackRequiresUserAction, BOOL)
58 59
 #if WEBKIT_IOS_10_APIS_AVAILABLE