3

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?

tristanbbq
  • 595
  • 3
  • 15

2 Answers2

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"/>

mKane
  • 932
  • 13
  • 30
  • 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)? – Justin Michael Oct 20 '18 at 06:18
  • Then you wouldn't use the PasswordAutofill API. Just ask them their email address and mark it as so. – mKane Oct 20 '18 at 20:41
  • AFAIK, Apple doesn't allow us to use Autofill in WKWebview because the app may steal your information. – Hwangho Kim Feb 28 '20 at 07:41
  • Hmm, last I checked that wasn't true. It all depends what the html page looks like. – mKane Feb 28 '20 at 19:07
1

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

Dave Smash
  • 2,941
  • 1
  • 18
  • 38