瀏覽代碼

fix(iOS): add basicAuthCredential prop

iwashita 4 年之前
父節點
當前提交
7b1899f5cd
共有 3 個檔案被更改,包括 11 行新增0 行删除
  1. 1
    0
      apple/RNCWebView.h
  2. 9
    0
      apple/RNCWebView.m
  3. 1
    0
      apple/RNCWebViewManager.m

+ 1
- 0
apple/RNCWebView.h 查看文件

@@ -64,6 +64,7 @@
64 64
 @property (nonatomic, copy) NSString * _Nullable allowingReadAccessToURL;
65 65
 @property (nonatomic, assign) BOOL pullToRefreshEnabled;
66 66
 @property (nonatomic, weak) UIRefreshControl * refreshControl;
67
+@property (nonatomic, copy) NSDictionary * _Nullable basicAuthCredential;
67 68
 
68 69
 #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* iOS 13 */
69 70
 @property (nonatomic, assign) WKContentMode contentMode;

+ 9
- 0
apple/RNCWebView.m 查看文件

@@ -781,6 +781,15 @@ static NSDictionary* customCertificatesForHost;
781 781
             }
782 782
         }
783 783
     }
784
+    if ([[challenge protectionSpace] authenticationMethod] == NSURLAuthenticationMethodHTTPBasic) {
785
+        NSString *username = [_basicAuthCredential valueForKey:@"username"];
786
+        NSString *password = [_basicAuthCredential valueForKey:@"password"];
787
+        if (username && password) {
788
+            NSURLCredential *credential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceNone];
789
+            completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
790
+            return;
791
+        }
792
+    }
784 793
     completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
785 794
 }
786 795
 

+ 1
- 0
apple/RNCWebViewManager.m 查看文件

@@ -75,6 +75,7 @@ RCT_EXPORT_VIEW_PROPERTY(applicationNameForUserAgent, NSString)
75 75
 RCT_EXPORT_VIEW_PROPERTY(cacheEnabled, BOOL)
76 76
 RCT_EXPORT_VIEW_PROPERTY(allowsLinkPreview, BOOL)
77 77
 RCT_EXPORT_VIEW_PROPERTY(allowingReadAccessToURL, NSString)
78
+RCT_EXPORT_VIEW_PROPERTY(basicAuthCredential, NSDictionary)
78 79
 
79 80
 #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
80 81
 RCT_EXPORT_VIEW_PROPERTY(contentInsetAdjustmentBehavior, UIScrollViewContentInsetAdjustmentBehavior)