0

I am using a WKWebView to present a login page to the user. After logging in, I would like to retrieve the users ID. Initially wanted to include this in the Response Header, but apparently this is not possbile: AFAIK sadly you cannot do this with WKWebView.

It most certainly does not work in webView:decidePolicyForNavigationAction:decisionHandler: because the navigationAction.request is read-only and a non-mutable NSURLRequest instance that you cannot change.

How To add HttpHeader in request globally for ios swift

As an alternative approach, I will attempt to add a hidden html field to the Response body:

<input type="hidden" name="userID" value="The retrieved userID">

How do I extract this value?

Martin Muldoon
  • 3,388
  • 4
  • 24
  • 55
  • You should rather use Javascript bridge. When user logs in, Javascript executes a function in native code. Take a look at this article: http://www.joshuakehn.com/2014/10/29/using-javascript-with-wkwebview-in-ios-8.html – mag_zbc Jul 11 '17 at 15:12
  • @mag_zbc I'm really looking for a simple solution. I think I'll drop WKWebView and just use UIWebView. I'll add the user ID to the response header. For now, it will do. Thanks. – Martin Muldoon Jul 11 '17 at 22:03

0 Answers0