问题描述
1Password 和 LastPass 都使用相同的方案(org-appextension-feature-password-management
)进行密码管理.这允许 3rd 方应用程序使用 onepassword-app-extension 来处理其中任何一个密码管理器.
Both 1Password and LastPass utilize the same scheme (org-appextension-feature-password-management
) for password management. This allows 3rd party apps to use the onepassword-app-extension to work with any of these password managers.
如果我想实现自己的与此扩展程序兼容的密码管理器,我需要做什么?
If I want to implement my own password manager which is compatible with this extension, what do I need to do?
推荐答案
实现密码管理器:
为您的项目添加一个新目标.选择操作扩展".
Add a new target to your project. Choose "Action Extension."
添加 org-appextension-feature-password-management
作为您的应用支持的 URL Scheme (CFBundleURLSchemes
).
Add org-appextension-feature-password-management
as a URL Scheme (CFBundleURLSchemes
) that your app supports.
您可以在目标的信息"选项卡中执行此操作.方案是重要的部分.似乎没有使用标识符.
You can do this in the Info tab of your target. The scheme is the important part. The identifier doesn't seem to be used.
这是必需的,以便 -[OnePasswordExtension isAppExtensionAvailable]
将返回 true.
This is required so that -[OnePasswordExtension isAppExtensionAvailable]
will return true.
在您的应用扩展程序的目标中,将 NSExtensionActivationRule
从 TRUEPREDICATE
更改为以下内容:
In your app extension's target, change the NSExtensionActivationRule
from TRUEPREDICATE
to the following:
SUBQUERY (
extensionItems,
$extensionItem,
SUBQUERY (
$extensionItem.attachments,
$attachment,
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "org.appextension.find-login-action"
).@count == $extensionItem.attachments.@count
).@count == 1
这将确保您的扩展程序仅在 -[OnePasswordExtension findLoginForURLString:forViewController:sender:completion:]
方法被调用时出现.如果您想匹配多个 UTI,请参阅 苹果更复杂的例子在这里.
This will make sure your extension only appears if the -[OnePasswordExtension findLoginForURLString:forViewController:sender:completion:]
method is called. If you want to match more than one of these UTIs, see Apple's more complex example here.
注意:此 SUBQUERY 与 Apple 的 SUBQUERY 示例,常量已更改.如果您想知道语法或其工作原理,请查看此答案.
Note: This SUBQUERY is the same as Apple's SUBQUERY example, with the constant changed. If you're wondering about the syntax or how it works, see this answer.
读取应填写的网址:
let inputItem = extensionContext!.inputItems[0] as! NSExtensionItem
let inputItemProvider = inputItem.attachments![0] as! NSItemProvider
inputItemProvider.loadItem(forTypeIdentifier: "org.appextension.find-login-action", options: nil) { (data, err) in
if let err = err { fatalError("\(err)") }
let urlString = (data as! NSDictionary)["url_string"] as! String
}
当您准备好将数据从扩展程序发送回主机应用程序时:
When you're ready to send data from the extension back to the host app:
let itemProvider = NSItemProvider(
item: ["username": "foo", "password": "123"],
typeIdentifier:kUTTypePropertyList as String) // TODO: import MobileCoreServices
let extensionItem = NSExtensionItem()
extensionItem.attachments = [itemProvider]
extensionContext!.completeRequestReturningItems([extensionItem], completionHandler: nil)
如果您想知道为什么可以注册这些方案,您可以阅读这篇文章:
我们的品牌中立方案应该让用户和应用开发者都更轻松.因此,我们使用品牌中立方案的部分原因是鼓励尽可能多的应用开发者使用该方案.我们不会强迫应用开发者在 1Password 和某些竞争对手之间做出选择.相反,我们将使用哪个密码管理器的选择权委托给该选择所属的地方:您.
这篇关于如何制作兼容的密码扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!