瀏覽代碼

Update RNCWebView.m

Added support for opening pdf files in ios 13
eladgel 5 年之前
父節點
當前提交
562e8321b4
No account linked to committer's email address
共有 1 個檔案被更改,包括 11 行新增3 行删除
  1. 11
    3
      ios/RNCWebView.m

+ 11
- 3
ios/RNCWebView.m 查看文件

461
         return;
461
         return;
462
     }
462
     }
463
     if (request.URL.host) {
463
     if (request.URL.host) {
464
-        [_webView loadRequest:request];
465
-    }
466
-    else {
464
+        NSString *path = [request.URL path];
465
+                   NSString *extension = [path pathExtension];
466
+        NSString* absolutePath = request.URL.absoluteString;
467
+        if (@available(iOS 13, *) && [extension caseInsensitiveCompare:@"pdf"] == NSOrderedSame) {
468
+            NSData *pdfData = [NSData dataWithContentsOfURL:request.URL];
469
+            [self.webView loadData:pdfData MIMEType:@"application/pdf" characterEncodingName:[NSString string] baseURL:[NSURL URLWithString:absolutePath]];
470
+           
471
+        } else {
472
+            [_webView loadRequest:request];
473
+        }
474
+    } else {
467
         NSURL* readAccessUrl = _allowingReadAccessToURL ? [RCTConvert NSURL:_allowingReadAccessToURL] : request.URL;
475
         NSURL* readAccessUrl = _allowingReadAccessToURL ? [RCTConvert NSURL:_allowingReadAccessToURL] : request.URL;
468
         [_webView loadFileURL:request.URL allowingReadAccessToURL:readAccessUrl];
476
         [_webView loadFileURL:request.URL allowingReadAccessToURL:readAccessUrl];
469
     }
477
     }