5

Inputs with autocomplete enabled are working properly when opening in mobile Safari but not when loaded in a WKWebview (iOS 11.3). Is this a known limitation?

3
  • Are you using a framework such as Ionic or something? Commented Apr 23, 2018 at 20:51
  • How doesn't it work? Commented Apr 23, 2018 at 20:57
  • No framework. Just plain html <input> with autocomplete="email" @Ryan on Safari I get the email suggestion in my keyboard, in the WKWebview it just doesn't offer anything Commented Apr 24, 2018 at 14:29

2 Answers 2

2

I know I'm late to the party, but I had a surprisingly hard time finding a solution to such an old problem, so I wanted to share since this is still high on the Google results.

The autofill that I wanted was for the WKWebView to autocomplete a saved username and password for easy login. However, this could present a security risk to the user, so you have to add the "Associated Domains" entitlement to the iOS app that tells it which domains/subdomains it can trust, and you have to add a JSON file to the web site server's wwwroot/.well-known directory to prove that you control the site you are displaying in the WKWebView. Once that is done, then the username/password is autosuggested the same way that it is in Safari.

Here is the Apple documentation: https://developer.apple.com/documentation/xcode/supporting-associated-domains

To summarize the steps I took, in XCode, I went to the "Signing and Capabilities" tab in my app target, clicked the "+ Capability" button, added Associated Domains, and put entries in the newly created list for all of my subdomains:

webcredentials:example.com
webcredentials:www.example.com
webcredentials:othersubdomain.example.com

And then on my web server, I added a file to the .well-known directory called "apple-app-site-association" (no extension) with the following contents:

{
  "webcredentials": {
    "apps": [ "ABCDE12345.com.example.myapp" ]
  }
}

(where the format for the identifier is <Application Identifier Prefix>.<Bundle Identifier>). Then I browsed to https://www.example.com/.well-known/apple-app-site-association to make sure that the json was displayed in the browser.

Note: I use ASP.Net Core MVC, and the file WASN'T displayed in the browser since it doesn't use a recognized file extension. I found several methods for getting around that - I chose to add a file extension to the file and then use a rewrite rule in startup.cs so that Apple can find the file without supplying the extension in the request. You can find more on that at asp.net core - How to serve static file with no extension

Sign up to request clarification or add additional context in comments.

1 Comment

Inputs still don't have suggestions or access to passwords after this.
1

https://developer.apple.com/documentation/security/password_autofill/enabling_password_autofill_on_an_html_input_element?language=objc

Try using the below format to get html autofilling your fields

<input id="user-text-field" type="email" autocomplete="username"/>

4 Comments

This works fine if you're after email-as-username autofill, but what if you just want their email address (i.e. not as a username)?
Then you wouldn't use the PasswordAutofill API. Just ask them their email address and mark it as so.
AFAIK, Apple doesn't allow us to use Autofill in WKWebview because the app may steal your information.
Hmm, last I checked that wasn't true. It all depends what the html page looks like.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.