Implementing AutoFill Credential Provider Extension in iOS14

Hi everyone! I’m new here!

I am trying to create a Password Management app. I noticed that online there are very few resources that help you do that. Specifically, there are almost no detailed resources on implementing the AutoFill Credential Provider Extension.

There’s the video of the WWDC where they presented this feature, but don’t explain in detail how to use it.

Is there someone that has already done it that could help me?

Right now, I added the AutoFill Credential Provider capability as well as the AutoFill Credential Provider extension, which right now looks like this:

import AuthenticationServices

class CredentialProviderViewController: ASCredentialProviderViewController {

    override func prepareCredentialList(for serviceIdentifiers: [ASCredentialServiceIdentifier]) {
    }
    
    override func provideCredentialWithoutUserInteraction(for credentialIdentity: ASPasswordCredentialIdentity) {
        let databaseIsUnlocked = true
        if (databaseIsUnlocked) {
            let passwordCredential = ASPasswordCredential(user: "j_appleseed", password: "apple1234")
            self.extensionContext.completeRequest(withSelectedCredential: passwordCredential, completionHandler: nil)
        } else {
            self.extensionContext.cancelRequest(withError: NSError(domain: ASExtensionErrorDomain, code:ASExtensionError.userInteractionRequired.rawValue))
        }
    }

    override func prepareInterfaceToProvideCredential(for credentialIdentity: ASPasswordCredentialIdentity) {
    }

    @IBAction func cancel(_ sender: AnyObject?) {
        self.extensionContext.cancelRequest(withError: NSError(domain: ASExtensionErrorDomain, code: ASExtensionError.userCanceled.rawValue))
    }

    @IBAction func passwordSelected(_ sender: AnyObject?) {
        let passwordCredential = ASPasswordCredential(user: "j_appleseed", password: "apple1234")
        self.extensionContext.completeRequest(withSelectedCredential: passwordCredential, completionHandler: nil)
    }
}

All of this was pre-written, but on the line

} else {

self.extensionContext.cancelRequest(withError: NSError(domain: ASExtensionErrorDomain, code:ASExtensionError.userInteractionRequired.rawValue))

}

I get the yellow warning “Will never be executed”. Can someone help me understand how this extension works? Or is there a guide that I can follow? I can’t find any nor on this website nor elsewhere on the internet.

Hi Pandruz welcome to the community!

Sorry I haven’t used this before. Hopefully someone else in the community can chime in.

Sometimes you could try looking up the speaker and seeing if they’re on Twitter. If they are tweet them (don’t DM) and ask them “hey I don’t understand how to do XYZ. I understood up until this point XX:XX in the talk”

I don’t have Twitter :sweat_smile: