Xamarin IoS 12 update: WKWebView custom renderer issue












0














I'm facing with a very weird issue with a Xamarin Forms application on IoS after the latest OS update. Basically this application uses a WebView renderer to navigate a company's intranet portal which has NTLM authentication. I implemented the web renderer to handle the authentication process and it was working fine till few week ago but after Apple's last update the webview has stopped working.
Unfortunately there is no error code, exception or explicit message from the SDK, and the authentication process is working (I can see it from the logs), by the way the webview's content is all blank.
I have tried to navigate to other websites (with no authentication) too (bing.com, google.com, xamarin.com) but the issue was still there.



Anyone has some suggestion or hint?



UPDATE



After a deep investigation I've finally found the problem! Actually it seems that after the deprecation of UIWebview when using a custom renderer to handle authentication scenarios you cannot skip the HTTP 200 response (as suggested before) otherwise the component won't load the html contents!



So this is what I had before in my custom renderer:



public override void DecidePolicy(WKWebView webView, WKNavigationResponse navigationResponse, Action<WKNavigationResponsePolicy> decisionHandler)
{
var url = navigationResponse?.Response?.Url;
if (url == null) return;

if (navigationResponse.Response is NSHttpUrlResponse)
{
var resp = navigationResponse.Response as NSHttpUrlResponse;
if (resp.StatusCode == 200) return;
HandleHttpResponse(resp);
decisionHandler(WKNavigationResponsePolicy.Allow);

}
else if (navigationResponse.Response is NSUrlResponse)
{
//todo handle this case too if we want to open excel files in webview
//UIApplication.SharedApplication.OpenUrl(url);
decisionHandler(WKNavigationResponsePolicy.Cancel);
}

}


and this is what I have changed:



var resp = navigationResponse.Response as NSHttpUrlResponse;
//if (resp.StatusCode == 200) return;
HandleHttpResponse(resp);
decisionHandler(WKNavigationResponsePolicy.Allow);


Just commenting the if for StatusCode 200 and let contine with decisionHandler it works... Very very weird!










share|improve this question
























  • Apple WebView API is deprecated, you need to use in your xamarin as WKWebView.
    – Harjot Singh
    Nov 21 '18 at 14:17










  • developer.xamarin.com/api/type/WebKit.WKWebView for your reference
    – Harjot Singh
    Nov 21 '18 at 14:18










  • Hi Harjot, I'm already using WKWebView
    – Saverio Guardato
    Nov 21 '18 at 17:04










  • Glad you have found your solution.
    – Harjot Singh
    Nov 22 '18 at 11:48
















0














I'm facing with a very weird issue with a Xamarin Forms application on IoS after the latest OS update. Basically this application uses a WebView renderer to navigate a company's intranet portal which has NTLM authentication. I implemented the web renderer to handle the authentication process and it was working fine till few week ago but after Apple's last update the webview has stopped working.
Unfortunately there is no error code, exception or explicit message from the SDK, and the authentication process is working (I can see it from the logs), by the way the webview's content is all blank.
I have tried to navigate to other websites (with no authentication) too (bing.com, google.com, xamarin.com) but the issue was still there.



Anyone has some suggestion or hint?



UPDATE



After a deep investigation I've finally found the problem! Actually it seems that after the deprecation of UIWebview when using a custom renderer to handle authentication scenarios you cannot skip the HTTP 200 response (as suggested before) otherwise the component won't load the html contents!



So this is what I had before in my custom renderer:



public override void DecidePolicy(WKWebView webView, WKNavigationResponse navigationResponse, Action<WKNavigationResponsePolicy> decisionHandler)
{
var url = navigationResponse?.Response?.Url;
if (url == null) return;

if (navigationResponse.Response is NSHttpUrlResponse)
{
var resp = navigationResponse.Response as NSHttpUrlResponse;
if (resp.StatusCode == 200) return;
HandleHttpResponse(resp);
decisionHandler(WKNavigationResponsePolicy.Allow);

}
else if (navigationResponse.Response is NSUrlResponse)
{
//todo handle this case too if we want to open excel files in webview
//UIApplication.SharedApplication.OpenUrl(url);
decisionHandler(WKNavigationResponsePolicy.Cancel);
}

}


and this is what I have changed:



var resp = navigationResponse.Response as NSHttpUrlResponse;
//if (resp.StatusCode == 200) return;
HandleHttpResponse(resp);
decisionHandler(WKNavigationResponsePolicy.Allow);


Just commenting the if for StatusCode 200 and let contine with decisionHandler it works... Very very weird!










share|improve this question
























  • Apple WebView API is deprecated, you need to use in your xamarin as WKWebView.
    – Harjot Singh
    Nov 21 '18 at 14:17










  • developer.xamarin.com/api/type/WebKit.WKWebView for your reference
    – Harjot Singh
    Nov 21 '18 at 14:18










  • Hi Harjot, I'm already using WKWebView
    – Saverio Guardato
    Nov 21 '18 at 17:04










  • Glad you have found your solution.
    – Harjot Singh
    Nov 22 '18 at 11:48














0












0








0







I'm facing with a very weird issue with a Xamarin Forms application on IoS after the latest OS update. Basically this application uses a WebView renderer to navigate a company's intranet portal which has NTLM authentication. I implemented the web renderer to handle the authentication process and it was working fine till few week ago but after Apple's last update the webview has stopped working.
Unfortunately there is no error code, exception or explicit message from the SDK, and the authentication process is working (I can see it from the logs), by the way the webview's content is all blank.
I have tried to navigate to other websites (with no authentication) too (bing.com, google.com, xamarin.com) but the issue was still there.



Anyone has some suggestion or hint?



UPDATE



After a deep investigation I've finally found the problem! Actually it seems that after the deprecation of UIWebview when using a custom renderer to handle authentication scenarios you cannot skip the HTTP 200 response (as suggested before) otherwise the component won't load the html contents!



So this is what I had before in my custom renderer:



public override void DecidePolicy(WKWebView webView, WKNavigationResponse navigationResponse, Action<WKNavigationResponsePolicy> decisionHandler)
{
var url = navigationResponse?.Response?.Url;
if (url == null) return;

if (navigationResponse.Response is NSHttpUrlResponse)
{
var resp = navigationResponse.Response as NSHttpUrlResponse;
if (resp.StatusCode == 200) return;
HandleHttpResponse(resp);
decisionHandler(WKNavigationResponsePolicy.Allow);

}
else if (navigationResponse.Response is NSUrlResponse)
{
//todo handle this case too if we want to open excel files in webview
//UIApplication.SharedApplication.OpenUrl(url);
decisionHandler(WKNavigationResponsePolicy.Cancel);
}

}


and this is what I have changed:



var resp = navigationResponse.Response as NSHttpUrlResponse;
//if (resp.StatusCode == 200) return;
HandleHttpResponse(resp);
decisionHandler(WKNavigationResponsePolicy.Allow);


Just commenting the if for StatusCode 200 and let contine with decisionHandler it works... Very very weird!










share|improve this question















I'm facing with a very weird issue with a Xamarin Forms application on IoS after the latest OS update. Basically this application uses a WebView renderer to navigate a company's intranet portal which has NTLM authentication. I implemented the web renderer to handle the authentication process and it was working fine till few week ago but after Apple's last update the webview has stopped working.
Unfortunately there is no error code, exception or explicit message from the SDK, and the authentication process is working (I can see it from the logs), by the way the webview's content is all blank.
I have tried to navigate to other websites (with no authentication) too (bing.com, google.com, xamarin.com) but the issue was still there.



Anyone has some suggestion or hint?



UPDATE



After a deep investigation I've finally found the problem! Actually it seems that after the deprecation of UIWebview when using a custom renderer to handle authentication scenarios you cannot skip the HTTP 200 response (as suggested before) otherwise the component won't load the html contents!



So this is what I had before in my custom renderer:



public override void DecidePolicy(WKWebView webView, WKNavigationResponse navigationResponse, Action<WKNavigationResponsePolicy> decisionHandler)
{
var url = navigationResponse?.Response?.Url;
if (url == null) return;

if (navigationResponse.Response is NSHttpUrlResponse)
{
var resp = navigationResponse.Response as NSHttpUrlResponse;
if (resp.StatusCode == 200) return;
HandleHttpResponse(resp);
decisionHandler(WKNavigationResponsePolicy.Allow);

}
else if (navigationResponse.Response is NSUrlResponse)
{
//todo handle this case too if we want to open excel files in webview
//UIApplication.SharedApplication.OpenUrl(url);
decisionHandler(WKNavigationResponsePolicy.Cancel);
}

}


and this is what I have changed:



var resp = navigationResponse.Response as NSHttpUrlResponse;
//if (resp.StatusCode == 200) return;
HandleHttpResponse(resp);
decisionHandler(WKNavigationResponsePolicy.Allow);


Just commenting the if for StatusCode 200 and let contine with decisionHandler it works... Very very weird!







ios xamarin.forms wkwebview custom-renderer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 18:56







Saverio Guardato

















asked Nov 21 '18 at 14:12









Saverio GuardatoSaverio Guardato

1415




1415












  • Apple WebView API is deprecated, you need to use in your xamarin as WKWebView.
    – Harjot Singh
    Nov 21 '18 at 14:17










  • developer.xamarin.com/api/type/WebKit.WKWebView for your reference
    – Harjot Singh
    Nov 21 '18 at 14:18










  • Hi Harjot, I'm already using WKWebView
    – Saverio Guardato
    Nov 21 '18 at 17:04










  • Glad you have found your solution.
    – Harjot Singh
    Nov 22 '18 at 11:48


















  • Apple WebView API is deprecated, you need to use in your xamarin as WKWebView.
    – Harjot Singh
    Nov 21 '18 at 14:17










  • developer.xamarin.com/api/type/WebKit.WKWebView for your reference
    – Harjot Singh
    Nov 21 '18 at 14:18










  • Hi Harjot, I'm already using WKWebView
    – Saverio Guardato
    Nov 21 '18 at 17:04










  • Glad you have found your solution.
    – Harjot Singh
    Nov 22 '18 at 11:48
















Apple WebView API is deprecated, you need to use in your xamarin as WKWebView.
– Harjot Singh
Nov 21 '18 at 14:17




Apple WebView API is deprecated, you need to use in your xamarin as WKWebView.
– Harjot Singh
Nov 21 '18 at 14:17












developer.xamarin.com/api/type/WebKit.WKWebView for your reference
– Harjot Singh
Nov 21 '18 at 14:18




developer.xamarin.com/api/type/WebKit.WKWebView for your reference
– Harjot Singh
Nov 21 '18 at 14:18












Hi Harjot, I'm already using WKWebView
– Saverio Guardato
Nov 21 '18 at 17:04




Hi Harjot, I'm already using WKWebView
– Saverio Guardato
Nov 21 '18 at 17:04












Glad you have found your solution.
– Harjot Singh
Nov 22 '18 at 11:48




Glad you have found your solution.
– Harjot Singh
Nov 22 '18 at 11:48












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413977%2fxamarin-ios-12-update-wkwebview-custom-renderer-issue%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413977%2fxamarin-ios-12-update-wkwebview-custom-renderer-issue%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen