OGeek|极客世界-中国程序员成长平台

标题: ios - 如何制作兼容的密码扩展? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 11:53
标题: ios - 如何制作兼容的密码扩展?

1Password 和 LastPass 使用相同的方案 (org-appextension-feature-password-management) 进行密码管理。这允许第三方应用程序使用 onepassword-app-extension与这些密码管理器中的任何一个一起工作。

如果我想实现我自己的与此扩展兼容的密码管理器,我需要做什么?



Best Answer-推荐答案


实现密码管理器:

  1. 向您的项目添加一个新目标。选择“操作扩展”。

  2. org-appextension-feature-password-management 添加为您的应用支持的 URL Scheme (CFBundleURLSchemes)。

    您可以在目标的“信息”选项卡中执行此操作。该方案是重要的部分。 identifier doesn't seem to be used .

    这是必需的,以便 -[OnePasswordExtension isAppExtensionAvailable] 将返回 true。

  3. 在您的应用扩展的目标中,将 NSExtensionActivationRuleTRUEPREDICATE 更改为以下内容:

    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 中的多个,请参阅 Apple's more complex example here .

    注意:此子查询与 Apple's SUBQUERY example 相同, 随着常数的变化。如果您想了解语法或它是如何工作的,see this answer .

  4. 读取应该填写的url:

    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
    }
    
  5. 当您准备好将数据从扩展发送回主机应用时:

    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)
    

如果您想知道为什么可以注册这些方案,您可以read this article :

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 encourage as many app developers as possible to use this scheme. 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.

关于ios - 如何制作兼容的密码扩展?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38819916/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4