Add suggested passwords in AutoFill
This commit is contained in:
parent
156588bd93
commit
d4669bbfcb
4 changed files with 94 additions and 6 deletions
|
|
@ -35,6 +35,8 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
|
|||
override func prepareCredentialList(for serviceIdentifiers: [ASCredentialServiceIdentifier]) {
|
||||
let url = serviceIdentifiers.first.flatMap { URL(string: $0.identifier) }
|
||||
passwordsViewController.navigationItem.prompt = url?.host
|
||||
let keywords = url?.host?.sanitizedDomain?.components(separatedBy: ".") ?? []
|
||||
passwordsViewController.showPasswordsWithSuggstion(keywords)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -50,3 +52,14 @@ extension CredentialProviderViewController: PasswordSelectionDelegate {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension String {
|
||||
var sanitizedDomain: String? {
|
||||
replacingOccurrences(of: ".com", with: "")
|
||||
.replacingOccurrences(of: ".org", with: "")
|
||||
.replacingOccurrences(of: ".edu", with: "")
|
||||
.replacingOccurrences(of: ".net", with: "")
|
||||
.replacingOccurrences(of: ".gov", with: "")
|
||||
.replacingOccurrences(of: "www.", with: "")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,18 +27,27 @@ class PasswordsViewController: UIViewController {
|
|||
return uiSearchController
|
||||
}()
|
||||
|
||||
lazy var searchBar: UISearchBar = {
|
||||
self.searchController.searchBar
|
||||
}()
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
navigationItem.searchController = searchController
|
||||
navigationItem.hidesSearchBarWhenScrolling = false
|
||||
|
||||
searchController.searchBar.delegate = self
|
||||
searchBar.delegate = self
|
||||
|
||||
tableView.delegate = self
|
||||
tableView.dataSource = dataSource
|
||||
}
|
||||
|
||||
func showPasswordsWithSuggstion(_ keywords: [String]) {
|
||||
dataSource.showTableEntriesWithSuggestion(matching: keywords)
|
||||
tableView.reloadData()
|
||||
}
|
||||
|
||||
@IBAction
|
||||
private func cancel(_: AnyObject?) {
|
||||
self.extensionContext?.cancelRequest(withError: NSError(domain: ASExtensionErrorDomain, code: ASExtensionError.userCanceled.rawValue))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue