【问题标题】:Keychain not firing on iOS钥匙串没有在 iOS 上触发
【发布时间】:2019-06-22 01:56:16
【问题描述】:

钥匙串不会在 iOS 上自动填充我的登录表单。

在 xCode 中,我将 Keychain Sharing 设置为 on,并且在两个步骤旁边都有复选标记:将 Keychain Sharing 权利添加到您的权利文件并将 Keychain Sharing 功能添加到您的 App ID。

              <TextField
                class="input"
                hint="Email"
                keyboardType="email"
                autocorrect="false"
                autocapitalizationType="none"
                v-model="user.email"
                returnKeyType="next"
                @returnPress="focusPassword"
                fontSize="18"
              />
              <StackLayout class="hr-light"/>
            </StackLayout>

            <StackLayout class="input-field" marginBottom="15">
              <TextField
                ref="password"
                class="input"
                hint="Password"
                secure="true"
                v-model="user.password"
                :returnKeyType="isLoggingIn ? 'done' : 'next'"
                fontSize="18"
              />
              <StackLayout class="hr-light"/>
            </StackLayout> 

我很确定问题是我需要将 textContentType 设置为 .username 和 .password 但我不确定如何。

【问题讨论】:

    标签: ios nativescript nativescript-vue


    【解决方案1】:

    您必须在 nativeView 上设置 textContentType

    loaded 事件添加到TextField

          <TextField
                class="input"
                hint="Email"
                keyboardType="email"
                autocorrect="false"
                autocapitalizationType="none"
                v-model="user.email"
                returnKeyType="next"
                @loaded="onLoaded"
                @returnPress="focusPassword"
                fontSize="18"
              />
    

    在 nativeView 上更新 textContentType

    onLoaded: function(args) {
      const textField = args.object;
      if (textField.ios) {
         textField.ios.textContentType = UITextContentTypeEmailAddress;
      }
    }
    

    textContentType 应该是来自docs here 的值之一。

    还要确保您仅在 iOS 11 或更高版本上运行此代码。如果你支持 iOS 10,这行代码可能会抛出异常。如果您支持 iOS 10,则必须在 if 条件下检查平台版本。

    【讨论】:

    • 要检查 iOS 版本,您可以使用 iosUtils.MajorVersion from import { ios as iosUtils } from "tns-core-modules/utils/utils"
    • 是的,你可以用它来检查版本。
    • @Manoj 谢谢,但钥匙串仍然没有提示我。在我将 textField.ios.textContentType 设置为用户名和密码后,我正在记录它,它会记录 usernamepassword,正如我所期望的那样,但钥匙串仍然没有响应。我正在运行 iOS 12 并启用了钥匙串的物理设备上进行测试,因此我不应该遇到模拟器或旧操作系统的任何问题。还有其他想法吗?
    • 您是否已经注册并让应用程序存储新的电子邮件地址和密码?可以分享示例项目吗?
    • @Manoj 是的,我使用相同的用户名注册并多次通过。设备上启用了钥匙串和自动填充功能。不幸的是,我不能分享整个项目,因为它是我公司的私人仓库。 iOS应该提示我添加钥匙串还是自动这样做?抱歉,我是 Android 用户。
    猜你喜欢
    • 2014-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多