如何将短信中的代码正确插入文本字段?

问题描述

我使用一次性代码将短信中的代码插入文本字段,它可以工作,但是现在,在单击键盘顶部的代码后,我无法插入它。 希望你能帮帮我

Thats how does it look.

TextField("Введите код",text: $code.value).textContentType(.oneTimeCode)

我已经用过了,但是没有用

解决方法

View 上有一个修饰符,可让您设置内容类型,因此系统可以向用户建议输入:

func textContentType(_ textContentType: UITextContentType?) -> some View

您需要传入oneTimeCode

TextField("Enter code",text: $code)
    .textContentType(.oneTimeCode)