菜鸟教程小白 发表于 2022-12-12 11:53:14

ios - 如何制作兼容的密码扩展?


                                            <p><p>1Password 和 LastPass 使用相同的方案 (<code>org-appextension-feature-password-management</code>) 进行密码管理。这允许第三方应用程序使用 <a href="https://github.com/AgileBits/onepassword-app-extension" rel="noreferrer noopener nofollow">onepassword-app-extension</a>与这些密码管理器中的任何一个一起工作。</p>

<p>如果我想实现我自己的与此扩展兼容的密码管理器,我需要做什么?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>实现密码管理器:</p>

<ol>
<li><p>向您的项目添加一个新目标。选择“操作扩展”。</p></li>
<li><p>将 <code>org-appextension-feature-password-management</code> 添加为您的应用支持的 URL Scheme (<code>CFBundleURLSchemes</code>)。 </p>

<p>您可以在目标的“信息”选项卡中执行此操作。该方案是重要的部分。 <a href="https://stackoverflow.com/questions/16597631/url-identifier-and-url-scheme" rel="noreferrer noopener nofollow">identifier doesn&#39;t seem to be used</a> .</p>

<p>这是必需的,以便 <code>-</code> 将返回 true。</p></li>
<li><p>在您的应用扩展的目标中,将 <code>NSExtensionActivationRule</code> 从 <code>TRUEPREDICATE</code> 更改为以下内容:</p>

<pre><code>SUBQUERY (
extensionItems,
$extensionItem,
SUBQUERY (
    $extensionItem.attachments,
    $attachment,
    ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO &#34;org.appextension.find-login-action&#34;
).@count == $extensionItem.attachments.@count
).@count == 1
</code></pre>

<p>这将确保您的扩展仅在 <code>-</code> 方法被调用时出现。如果您想匹配这些 UTI 中的多个,请参阅 <a href="https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW1" rel="noreferrer noopener nofollow">Apple&#39;s more complex example here</a> .</p>

<p>注意:此子查询与 <a href="https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW1" rel="noreferrer noopener nofollow">Apple&#39;s SUBQUERY example</a> 相同, 随着常数的变化。如果您想了解语法或它是如何工作的,<a href="https://stackoverflow.com/a/3076702/35690" rel="noreferrer noopener nofollow">see this answer</a> .</p></li>
<li><p>读取应该填写的url:</p>

<pre><code>let inputItem = extensionContext!.inputItems as! NSExtensionItem
let inputItemProvider = inputItem.attachments! as! NSItemProvider

inputItemProvider.loadItem(forTypeIdentifier: &#34;org.appextension.find-login-action&#34;, options: nil) { (data, err) in
    if let err = err { fatalError(&#34;\(err)&#34;) }

    let urlString = (data as! NSDictionary)[&#34;url_string&#34;] as! String
}
</code></pre> </li>
<li><p>当您准备好将数据从扩展发送回主机应用时:</p>

<pre><code>let itemProvider = NSItemProvider(
    item: [&#34;username&#34;: &#34;foo&#34;, &#34;password&#34;: &#34;123&#34;],
    typeIdentifier:kUTTypePropertyList as String) // TODO: import MobileCoreServices

let extensionItem = NSExtensionItem()
extensionItem.attachments =

extensionContext!.completeRequestReturningItems(, completionHandler: nil)
</code></pre> </li>
</ol>

<hr/>

<p>如果您想知道为什么可以注册这些方案,您可以<a href="https://blog.agilebits.com/2014/08/04/filling-with-your-approval-on-1passwords-app-extension-and-ios-8-security/" rel="noreferrer noopener nofollow">read this article</a> :</p>

<blockquote>
<p>Our brand-neutral scheme should make things easier both for users and for app developers. Thus, part of our reason for using a brand neutral scheme is to <strong>encourage as many app developers as possible to use this scheme.</strong> We aren’t forcing app developers to choose between 1Password and some competitor. Instead, we are delegating the choice of which password manager to use to where that choice belongs: you.</p>
</blockquote></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何制作兼容的密码扩展?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/38819916/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/38819916/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何制作兼容的密码扩展?