• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-12 11:53:14 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap