
這篇文章將介紹密碼自動填充(Password AutoFill)如何與 iOS 和網(wǎng)頁應(yīng)用交互。
1. Password AutoFill 工作流程
密碼自動填充功能在以下幾個事件與 app 配合使用:
- 用戶首次安裝 app,如已在 Safari 保存密碼,可以直接點(diǎn)擊 QuickType bar 賬號信息登陸。
- 用戶注冊賬號時,自動生成強(qiáng)密碼,注冊成功后保存到 iCloud Keychain。
- 輸入短信驗(yàn)證碼時,點(diǎn)擊 QuickType bar 直接輸入。
在 iOS 系統(tǒng)安裝 app 后,系統(tǒng)會嘗試將 app 與 Associated Domains Entitlement 文件列出的域名進(jìn)行關(guān)聯(lián)。
- 系統(tǒng)獲取 Associated Domains Entitlement 中每個域名。
- 嘗試下載每個域名中 Apple App Site Association 文件(apple-app-site-associatio)。
- 如果上述步驟均成功,系統(tǒng)會將 app 與域名進(jìn)行關(guān)聯(lián),并為該域的憑據(jù)(credential)開啟 Password AutoFill 功能。
2. 設(shè)置 app、域名相互關(guān)聯(lián)
使用關(guān)聯(lián)域名(associated doumains)可以讓你的 app 和網(wǎng)站共享共享憑據(jù)(credentials)。
一個域名是一個網(wǎng)站。有時可能會想讓 app 和網(wǎng)站關(guān)聯(lián)起來,因?yàn)榫W(wǎng)站和 app 可能有不同版本的內(nèi)容,或其間想要共享數(shù)據(jù)。想要讓 app 和網(wǎng)站關(guān)聯(lián)起來,需要在網(wǎng)站放一個名稱為apple-app-site-association文件,在 app 上添加一個 entitlement。
除共享 credentials 外,通用鏈接(universal link)、Handoff也需要用到 associated domains entitlement。
在開始這篇文章前,先下載BasicDemos-iOS/PasswordAutoFill模版 ,在 Xcode 打開 PasswordAutofill.xcodeproj文件,并在真機(jī)運(yùn)行。如下:

在 Login In 頁面點(diǎn)擊 Sign Up 按鈕,在注冊頁面輸入用戶名、密碼,點(diǎn)擊 Sign Up 按鈕,會出現(xiàn)錯誤提示。目前,app 后端還沒有建立,無法注冊、登陸。
在上面下載的文件中,PasswordAutoFill-Server文件包含了 server app。這篇文章中,我們將把服務(wù)器部署在 Heroku,Heroku 提供了一種簡單、免費(fèi)的解決方案。如果你還沒有 Heroku 賬號,點(diǎn)擊https://signup.heroku.com/注冊即可。
2.1 創(chuàng)建 Heroku App
注冊賬號后,訪問https://dashboard.heroku.com并登陸。
點(diǎn)擊右上角的 New 按鈕,選擇 Create new app。在下一個頁面中,填寫 app 名稱,選擇部署地區(qū)。如果不填寫 app 名稱,系統(tǒng)會自動生成。最后點(diǎn)擊 Create app 按鈕。
創(chuàng)建完成后,會進(jìn)入 app 主頁。選擇 Resources 選項(xiàng)卡,在 Add-ons 部分,輸入 postgre,選擇 Heroku Postgres 選項(xiàng):

點(diǎn)擊 Heroku Postgres 后會進(jìn)入選擇 database 類型頁面,選擇 Hobby Dev - Free,點(diǎn)擊 Provision 按鈕,Heroku 會自動進(jìn)行創(chuàng)建工作。
完成后,數(shù)據(jù)庫將顯示在 Resources 選項(xiàng)卡下,表示 Web app 已經(jīng)創(chuàng)建完成。
2.2 App Identifier
描述文件(provisioning profile)使用 App ID 標(biāo)志你的 app,App ID 由兩部分組成,前綴是 Team ID,后綴是 Bundle ID,中間由句號 . 隔開。App ID中可以包含多個句號,每一部分都有重要用途。
App ID 有以下兩種類型:
- 顯式 App ID (explicit App ID):用于單個 app。
- 通配符 App ID (wildcard App ID):用于一組 app。
App 想要使用的服務(wù)都必須在 App ID 開啟??梢栽趧?chuàng)建 App ID 時啟用所需服務(wù),也可以在之后修改。在 explicit App ID 中,Game Center 和 In-App Purchase 服務(wù)默認(rèn)開啟。
截止到 Xcode 10.1,Wildcard App ID 只能使用 Data Protection、iCloud、Inter-App Audio、Network Extensions、SiriKit、Wallet六項(xiàng)服務(wù)。Explicit App ID 可以使用所有服務(wù)。
要使用 Password AutoFill 功能,需要開啟 Associated Domains 服務(wù),因此只能使用 explicit App ID。既可以在 https://developer.apple.com/account/ios/identifier/bundle/create 創(chuàng)建 App ID ,也可以在 Xcode > General > Signing 部分選擇 Team 直接創(chuàng)建。
在 https://developer.apple.com/account/ios/identifier/bundle 點(diǎn)擊 app 名稱,查看 Team ID 和 Bundle ID:

2.3 添加 Apple App Site Association 文件
接下來,添加apple-app-site-association文件到你的網(wǎng)站。
創(chuàng)建一個名稱為apple-app-site-association(沒有擴(kuò)展名)的文件,文件內(nèi)容是 JSON 格式的詞典。詞典內(nèi)容是網(wǎng)站想要關(guān)聯(lián)應(yīng)用的 app ID。如下所示:
{
"webcredentials": {
"apps": [
"D3KQX62K1A.com.example.pro648",
"D3KQX62K1A.com.example.pro648Demo"
]
}
}
App Identifiers 格式如下:
<Team Identifier>.<Bundle Identifier>
將該文件放到網(wǎng)站的 .well-known 目錄,或根目錄, Apple 推薦放到 .well-known目錄。如果放到 .well-known 目錄,文件的 URL 格式如下:
https://<full qualified domain>/.well-knwon/apple-app-site-association
必須使用https://托管該文件,且證書在有效期內(nèi),同時不能使用重定向。
打開 Terminal,cd到 PasswordAutoFill模版/PasswordAutoFill-Server 目錄。例如,如果將 BasicDemos-iOS文件倉庫克隆到了桌面,你可以輸入:
$ cd ~/Desktop/BasicDemos-iOS/PasswordAutoFill模版/PasswordAutoFill-Server
在 PasswordAutoFill-Server 內(nèi),創(chuàng)建 Public 目錄,在 Public目錄創(chuàng)建 .well-known 目錄:
$ mkdir -p Public/.well-known/
繼續(xù)輸入如下命令:
$ echo '{"webcredentials": {"apps": ["<#Team ID#>.<#Bundle ID#>"]}}' > Public/.well-known/apple-app-site-association
使用你的 Team ID、Bundle ID 替換上述命令中 Team ID、Bundle ID。
進(jìn)入 Finder,打開 PasswordAutoFill-Server/Public/.well-known/apple-app-site-association 文件,可以看到上述命令輸入的 JSON 內(nèi)容。如果不顯示 .well-known 文件,使用 command+shift+. 顯示隱藏文件夾。
2.4 設(shè)置 Heroku CLI
已經(jīng)設(shè)置好了 App ID,現(xiàn)在需要把 apple-app-site-association 上傳到 web app。我們將使用 Heroku CLI 工具上傳這些文件。
需要使用 Homebrew 安裝 Heroku CLI。如果你的電腦沒有安裝 Homebrew,在 Terminal 輸入如下命令:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
如果需要更新 Homebrew ,輸入如下命令:
$ brew update
使用 Homebrew 安裝 Heroku CLI:
$ brew install heroku/brew/heroku
安裝 Heroku CLI后,使用如下命令登陸 Heroku 賬號:
$ heroku login
上述命令會在瀏覽器打開登陸頁面。
登陸后可以使用如下命令確認(rèn)是否登陸成功:
$ heroku auth:whoami
上述命令會返回登陸郵件信息。
2.5 部署 Server App
Heroku 通過 Git 部署 server app,因此需要將 server app 放到 git 倉庫。
繼續(xù)在 Terminal 操作,輸入如下命令:
$ git int
$ git add .
$ git commit -m "Vapor Server"
$ heroku git:remote -a <Heroku app name>
通過上述命令,已經(jīng)把 server app 添加到本地 git repository。
因?yàn)?BasicDemos-iOS 已經(jīng)是一個 git 倉庫,如果你在該倉庫中繼續(xù)創(chuàng)建 git 倉庫,會涉及到 git 倉庫嵌套。如果你對嵌套 git 倉庫不熟悉,可以把 server app 放到其他位置再創(chuàng)建 git 倉庫。
如果你對 git 還不熟悉,可以查看我的另一篇文章:教你系統(tǒng)學(xué)習(xí)Git。
Heroku 使用 Buildpack 為 app 提供了構(gòu)建方法。在 Terminal 輸入如下命令為 app 設(shè)置 Buildpack:
$ heroku buildpacks:set https://github.com/vapor-community/heroku-buildpack
使用如下命令將 app 部署到 Heroku:
$ git push heroku master
上述命令會將本地 master 分支推送至 Heroku 遠(yuǎn)程倉庫,整個過程可能持續(xù)幾分鐘。
如果 Heroku 當(dāng)前部署堆棧版本與社區(qū) buildpack 不兼容,會導(dǎo)致推送失敗。錯誤消息將告訴你錯誤原因及解決方案。例如,錯誤提示可能會告訴你執(zhí)行如下命令:
$ heroku stack:set heroku-16 -a <your-application-name>根據(jù)錯誤提示進(jìn)行操作,最后再次
push即可。
Heroku 通常會在完成構(gòu)建后自動啟動 app。但也可以使用如下命令手動啟動 app:
$ heroku ps:scale web=1
要打開 web app,輸入如下命令:
$ heroku open
也可以在 Heroku dashboard 的 Settings > Domains and certificates 部分查看 web app URL:

目前為止,你已擁有該網(wǎng)站。該網(wǎng)站提供的 apple-app-site-association 文件用于識別你的 app,也就是網(wǎng)站已經(jīng)關(guān)聯(lián)你的 app。你可以在 https://[your-domain]/.well-known/apple-app-site-association 查看該文件。
2.6 添加 associated domains entitlement
現(xiàn)在配置 iOS app 識別你的網(wǎng)站,以完成相互關(guān)聯(lián)。
在 Xcode 打開PasswordAutoFill,選取 target,打開 General 選項(xiàng)卡,確保 Bundle Identifier、Team 與 apple-app-site-association 中的一致。
選擇 Capabilities 選項(xiàng)卡,找到 Associated Domains 選項(xiàng)并打開,點(diǎn)擊 + 添加 Heroku app 域名:

如果 App ID 的 Capabilities 設(shè)置正確,下面會出現(xiàn)兩個對號標(biāo)記。分別表示:
- 已為 app 添加 Associated Domains entitlement。
- 已為 App ID 開啟 Associated Domains 功能。
Domains 前綴為服務(wù)名稱,后綴為域名。其中,共享憑據(jù)(Shared web credentials)服務(wù)的前綴是webcredentials,通用鏈接(universal links)服務(wù)的前綴是applinks,Handoff服務(wù)前綴是activitycontinuation。格式如下:
// Shared web credentials
webcredentials:[your-domain]
// Universal links
applinks:[your-domain]
// Handoff
activitycontinuation:[your-domain]
現(xiàn)在,可以在 project navigator 看到 PasswordAutofill.entitlements 文件,Entitlements 文件以屬性列表的格式包含了剛才輸入的網(wǎng)址:

iOS 和 macOS 使用 Entitlements 授予 app 特定功能或安全權(quán)限。通過設(shè)置 entitlement 值,可以開啟 iCloud、push notifications、Apple Pay 等功能。
現(xiàn)在,已經(jīng)將 app 與網(wǎng)站關(guān)聯(lián)起來了。
3. 為 Text Input View 開啟密碼自動填充
當(dāng)用戶選擇了支持 Password AutoFill 功能的輸入視圖或 HTML 輸入元素時,密碼自動填充功能會將 QuickType bar 顯示在鍵盤上方,并根據(jù)輸入視圖類型顯示對應(yīng)選項(xiàng)。
iOS 10.0 中增加的textContentType指示文本輸入?yún)^(qū)域期望的文本類型。例如,emailAddress表示期望輸入郵箱地址。當(dāng)為文本輸入?yún)^(qū)域提供這一信息后,系統(tǒng)有時會自動選擇對應(yīng)類型鍵盤、改善鍵盤校正,或?qū)崿F(xiàn)其他功能。
每個 text-entry area 應(yīng)盡可能的精準(zhǔn),因此不能為一個textContentTyep屬性組合多個值。為了讓 text input view 顯示正確自動填充建議,需要為每個文本輸入視圖設(shè)置正確的textContentType屬性。這篇文章將用到以下常量:
-
username:iOS 11.0 中增加,期望輸入賬戶名。 -
password:iOS 11.0 中增加,期望輸入密碼。 -
newPassword:iOS 12.0 中增加,期望輸入新密碼。 -
oneTimeCode:iOS 12.0 中增加,期望輸入短信驗(yàn)證碼。
如果未標(biāo)記輸入類型,系統(tǒng)會使用啟發(fā)式(heuristics)算法自動識別視圖類型。顯式聲明視圖textContentType,可以提高密碼自動填充表現(xiàn)。例如:heuristics 默認(rèn)用戶名、密碼在同一個頁面。如果用戶名、密碼分布在多個頁面,顯式聲明輸入內(nèi)容類型才可以讓自動填充正確識別。
密碼自動填充支持輸入視圖、HTML 輸入元素。
打開 Xcode 中的API.swift文件,找到26行中的如下代碼:
static let baseURL = URL(string: "https://[your-domain]")
使用你的 Heroku app name 替換上面的[your-domain]。
Heroku 域名格式為:
[your-app-name].herokuapp.com,如:https://safe-ridge-91450.herokuapp.com/ 。
API.swift包含了與你的 server 通信的 API,例如:注冊、登陸、修改密碼、退出和隨機(jī)返回名人名言。這些 API 都已集成到模板中,替換域名后,身份驗(yàn)證應(yīng)正常工作。
3.1 New Paswords
App 和 網(wǎng)站雙向關(guān)聯(lián)后,系統(tǒng)會為textContentType為newPassword的 text-entry area 自動創(chuàng)建強(qiáng)密碼,
下面,將在代碼中實(shí)現(xiàn) strong password generation。進(jìn)入SignupViewController.swift文件,更新如下:
override func viewWillAppear(_ animated: Bool) {
...
usernameField.textContentType = .username
passwordField.textContentType = .newPassword
}
3.2 User Names and Passwords
iOS 設(shè)備上保存至少一個密碼,且開啟密碼自動填充時,QuickType Bar 才會出現(xiàn)。點(diǎn)擊 Key 標(biāo)志用戶可以查看、選擇設(shè)備上已有賬號、密碼,QuickType Bar 上會顯示 app associated domains 賬號信息。
進(jìn)入LoginViewController.swift,更新如下:
override func viewWillAppear(_ animated: Bool) {
...
usernameField.textContentType = .username
passwordField.textContentType = .password
}
使用 Password AutoFill 生成的密碼會自動添加到 Keychain,使用 iCloud 在設(shè)備間同步。手動輸入的賬號、密碼會提示是否保存到 Keychain :
想要讓 iOS 系統(tǒng)識別出新的 credentials ,需要做到以下兩點(diǎn):
- 登陸成功后,將賬號、密碼文本框從視圖層級移除。
- 只有當(dāng)賬號、密碼文本框不在視圖層級中時,才清空其內(nèi)容。
由于,app dismiss 了登陸視圖控制器,其自動滿足了上述條件,但登陸失敗時不要保存密碼。
打開SignupViewController.swift文件,滑動到viewWillDisappear(_:)方法,更新如下:
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(true)
view.endEditing(true)
if API.token == nil {
usernameField.text = nil
passwordField.text = nil
} else {
API.logout()
}
}
當(dāng)?shù)顷懗晒?,服?wù)器會返回 token,API.swift 類保存該變量到API.token。如果API.token為nil,則登陸失敗。這種情況下,在視圖消失前,將usernameField和passwordField設(shè)置為nil,防止無效的密碼保存到 keychain。
如果API.token不為nil,則為登陸成功。iOS 會自動保存 credentials 到用戶 keychain。
3.3 Security Code
如果系統(tǒng)可以識別出短信驗(yàn)證碼,驗(yàn)證碼會自動顯示在QuickType bar上,最多顯示三分鐘。如果想要查看短信驗(yàn)證碼在各種語言下是否可以正確識別,可以直接使用 Message 發(fā)送給自己。如果驗(yàn)證碼有下劃線,點(diǎn)擊后出現(xiàn)「拷貝驗(yàn)證碼」的提示,則系統(tǒng)可以識別該驗(yàn)證碼。
進(jìn)入OneTimeCodeViewController.swift文件,更新如下:
override func viewWillAppear(_ animated: Bool) {
...
oneTimeCodeField.textContentType = .oneTimeCode
}

如果 app 使用自定義輸入視圖輸入驗(yàn)證碼,iOS 無法呈現(xiàn) AutoFill UI,也就無法顯示 one time code。
3.4 點(diǎn)擊 AutoFill Item
當(dāng)用戶點(diǎn)擊 QuickType bar時,系統(tǒng)會要求其使用 Face ID 或 Touch ID 進(jìn)行驗(yàn)證。當(dāng) Face ID 或 Touch ID 出現(xiàn)時,app 將進(jìn)入 inactive 狀態(tài),觸發(fā) app delegate 的applicationWillResignActive(_:)和applicationDidBecomeActive(_:)方法。
在觸發(fā)上述方法時,不要移除用戶界面,否則系統(tǒng)將無法自動填充賬號信息。
當(dāng) app 進(jìn)入 inactive 狀態(tài)時,有時需要隱藏敏感信息。但登陸前 app 不包含敏感信息,也就沒有必要進(jìn)行隱藏。
用戶授權(quán)成功后,系統(tǒng)會將 first responder 設(shè)置為要自動填充的視圖,即使 app 阻止修改 first responder。隨后,自動填充對應(yīng)視圖。
文本內(nèi)容變化后會發(fā)送通知??梢允褂眠@些通知驗(yàn)證信息、更新用戶界面。例如,用戶名、密碼不為空時啟用登陸按鈕。
對于 iOS apps,視圖內(nèi)容變化后系統(tǒng)會發(fā)送textDidChangeNotification通知。此外,還會根據(jù)視圖類型,調(diào)用以下委托方法:
-
UITextField:系統(tǒng)調(diào)用UITextFieldDelegate協(xié)議的textField(_:shouldChangeCharactersIn:replacementString:)方法。 -
UITextView:系統(tǒng)調(diào)用UITextViewDelegate協(xié)議的textView(_: shouldChangeTextIn:replacementText:)方法。 - 遵守
UITextInput協(xié)議的自定義視圖:系統(tǒng)調(diào)用UIKeyInput協(xié)議中的insertText(_:)方法或replace(_:withText:)方法。
4. 為 HTML Input Element 開啟密碼自動填充
要確保 HTML input element 顯示正確的自動填充建議,需要為輸入元素設(shè)置autocomplete屬性。
使用如下autocomplete屬性:
| Credential | Autocomplete Values |
|---|---|
| User Name | username |
| Password | current-password |
| New Password | new-password |
| One-Time Code | one-time-code |
與 text input view 一樣,顯式設(shè)置autocomplete屬性可以確保 input element 被正確識別。
默認(rèn)情況下,系統(tǒng)根據(jù) input element autocomplete 值選擇鍵盤類型,但可以通過組合設(shè)置輸入元素 type 和 autocomplete 值來指定期望鍵盤類型。例如:如果用戶名為郵件,設(shè)置 autocomplete 屬性為 username,設(shè)置 type 屬性為 email。如下:
<input type="email" autocomplete="username" name="username" class="form-control" id="username"/>
<input type="password" autocomplete="current-password" name="password" class="form-control" id="password"/>
當(dāng)創(chuàng)建賬號或修改密碼時,使用new-password屬性:
<input type="password" autocomplete="current-password" name="oldPassword" class="form-control" id="oldPassword"/>
<input type="password" autocomplete="new-password" minlength="10" passwordrules="required:upper; required:lower; required:digit; max-consecutive:2" name="newPassword" class="form-control" id="newPassword"/>
此外,還可以自動填充短信驗(yàn)證碼:
<input id="single-factor-code-text-field" autocomplete="one-time-code"/>
5. 自定義密碼規(guī)則
雖然Password AutoFill 自動生成的密碼非常強(qiáng)大,但 app 有時需要指定自己的密碼規(guī)則,以便符合其他要求。
要自定義密碼規(guī)則,請使用UITextInputTraits協(xié)議中的passwordRules屬性,或網(wǎng)頁中 HTML input 元素中的passwordrules屬性。密碼規(guī)則必須符合如下格式:
required: (<identifier> | <character-class>), ..., (<identifier> | <character-class>); allowed: (<identifier> | <character-class>), ..., (<identifier> | <character-class>); max-consecutive: <non-negative-integer>
使用這些關(guān)鍵字指定規(guī)則:
-
required或allowed:required表示所有密碼必須都包含這些字符;allowed表示允許使用的字符。如果沒有使用allowed,則只使用requred字符;如果沒有使用requred,則只使用allowed字符;如果使用了兩者,則所有allowed和requred字符均可使用;如果都沒有使用,則所有 ASCII 可輸出字符都可使用。 - Character Classes:upper表示 A-Z,lower 表示 a-z,digit 表示 0-9,special 表示 -~!@#$%^&*_+=`|(){}[:;"'<>,.? ] 和空格,ascii-printable 表示所有 ASCII 可輸出字符,unicode 表示所有 unicode 字符。
- Maximum Length Key:使用
max-consecutive限制密碼中字符最多可以連續(xù)出現(xiàn)次數(shù)。如果規(guī)則中出現(xiàn)多次max-consecutive,則以最少的為準(zhǔn)。使用minlength、maxlength限制密碼長度。 - Custom Character Class:自定義字符類,使用方括號包圍。例如:[abcd] 只允許"a"、“b"、"c"、"d"。
- Non-negative Integer Class:<non-negative-integer> 為非負(fù)整數(shù)。
如果沒有設(shè)置passwordRules屬性,則使用默認(rèn)規(guī)則。即允許所有 ASCII 可輸出字符,如下:
allowed:ascii-printable;
可以組合關(guān)鍵字來設(shè)置密碼規(guī)則。如果有兩個密碼框,只需要為一個設(shè)置密碼規(guī)則。
密碼的長度不能少于12,且允許使用的字符至少包含以下兩類:ASCII 大寫字母、ASCII小寫字母和數(shù)字。如果你的密碼規(guī)則不符合上述要求,則會被忽略。
如果密碼規(guī)則為:至少10位,包含大寫、小寫、數(shù)字,最多連續(xù)兩位相同字符??梢詾?HTML 添加以下標(biāo)記:
<input type="password" minlength="10" passwordrules="required:upper; required:lower; requried:digit; max-consecutive:2">
如果UITextField密碼規(guī)則為:字母、數(shù)字、特殊符號隨意組合:
let newPasswordTextField = UITextField()
newPasswordTextField.passwordRules = UITextInputPasswordRules(descriptor:"allowed: uppper, lower, digit, [-().&@?’#,/"+]; minlength: 8;")
使用多個 character classes 等價于單獨(dú)指定一個集合所有 character classes 的容器類,但required例外:
allowed:upper; allowed:lower <=> allowed: upper, lower
required:upper; required: lower <=> required: upper; required:lower
Apple 提供了 Password Rules Validation Tool 來檢查生成的密碼是否符合 app 要求,也可以使用該工具創(chuàng)建自定義規(guī)則。
6. 調(diào)試 Associated Domains
在 iOS 設(shè)備安裝你的 app 后,系統(tǒng)會從 entitlement 文件獲取域名列表,并下載apple-app-site-association文件。對于每個 domain,iOS 拼接 /apple-app-site-association 或 /.well-known/apple-app-site-association 到域名,并從該 URL 下載文件,查看文件內(nèi)容是否包含 App ID。
如果網(wǎng)站使用不同的子域(例如,example.com、www.example.com、support.example.com),需要在
Associated Domains Entitlement文件單獨(dú)列出每個子域,每個子域都要包含 apple-app-site-association 文件。
出現(xiàn)以下情況時關(guān)聯(lián)會失敗:
- JSON 文件無效,或不包含當(dāng)前 App ID。
- 服務(wù)器返回錯誤代碼為 300 - 499,即包含重定向。
如果 server 返回錯誤代碼 500-599,即文件暫時不可訪問。系統(tǒng)會三小時后再次嘗試,最多嘗試八次。在開發(fā)過程中,可以通過刪除 app 讓修改的 association file 立即生效。
如果下載 app 后關(guān)聯(lián)失敗,可以通過 macOS 上的 控制臺 console 查看具體原因。打開 console ,在左上角選擇設(shè)備名稱,運(yùn)行 demo,在控制臺搜索欄輸入SWCD,可以查看關(guān)聯(lián)失敗原因。

可以看到嘗試關(guān)聯(lián) developer.apple.com 失敗,原因在于其 apple-app-site-association 文件沒有包含該 app ID。
Demo名稱:PasswordAutoFill
源碼地址:https://github.com/pro648/BasicDemos-iOS/tree/master/PasswordAutoFill
參考資料: