iOS Question vkwebview and user auth

tufanv

Expert
Licensed User
Longtime User
Hello,

One of my pdf files is under .htaccess protect user auth. I need to use vkwebview instead of normal webview so that user can zoom into pdf. I am using this to provide user and password :

B4X:
Sub WebView1_UserAndPasswordRequired (Host As String, Realm As String) As String()
   Return Array As String("user", "pass)
End Sub

but I get, you don't have authorization error. What am i doing wrong here ?
 

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,

the following Objc code ...

B4X:
#if ObjC
@end

@interface B4IWKWebViewDelegate:NSObject <WKNavigationDelegate, WKUIDelegate>
@end

@implementation B4IWKWebViewDelegate (new)
    - (void)webView:(WKWebView *)webView
        didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
        completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler{
        B4IArray* B4ICred = [B4IObjectWrapper raiseEvent:webView :@"_userandpasswordrequired:" :@[webView.URL.absoluteString]];
        NSArray* Cred = B4ICred.objectsData;
        NSURLCredential *UrlCred = [NSURLCredential credentialWithUser:Cred[0] password:Cred[1] persistence:NSURLCredentialPersistenceForSession];
        completionHandler(NSURLSessionAuthChallengeUseCredential,UrlCred);
    }
#End If

... will add this event:
B4X:
Sub WKWebView1_UserAndPasswordRequired (Url As String) As String()
    Return Array As String("user", "pass")
End Sub

Jan
 
Upvote 0
Top