Pārlūkot izejas kodu

Update RNCWebView.m

Added support for opening pdf files in ios 13
eladgel 5 gadus atpakaļ
vecāks
revīzija
562e8321b4
No account linked to committer's email address
1 mainītis faili ar 11 papildinājumiem un 3 dzēšanām
  1. 11
    3
      ios/RNCWebView.m

+ 11
- 3
ios/RNCWebView.m Parādīt failu

@@ -461,9 +461,17 @@ static NSDictionary* customCertificatesForHost;
461 461
         return;
462 462
     }
463 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 475
         NSURL* readAccessUrl = _allowingReadAccessToURL ? [RCTConvert NSURL:_allowingReadAccessToURL] : request.URL;
468 476
         [_webView loadFileURL:request.URL allowingReadAccessToURL:readAccessUrl];
469 477
     }