在 iOS 中阅读短信

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16187841/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 23:19:00  来源:igfitidea点击:

Read SMS message in iOS

iosswiftsmsappstore-approvalios12

提问by UBA_MobileTeam

I'm an iOS developer and i have tried to build a mobile application with automatic activation functionality, i found more than way to read SMS message but only using private API which will cause Apple rejection to my app.,i have two questions and appreciate any feedback can help me.

我是一名 iOS 开发人员,我曾尝试构建一个具有自动激活功能的移动应用程序,我发现不仅可以读取 SMS 消息,而且只能使用私有 API,这会导致 Apple 拒绝我的应用程序。我有两个问题,非常感谢任何反馈都可以帮助我。

1- Is there any way to read SMS message in iOS platform without facing Apple rejection ? 2- Can anybody provide me with the related section in Apple developer documentation, the section that describe that its not allowed to read SMS message in iOS platform ?

1- 有没有办法在 iOS 平台上阅读 SMS 消息而不会被苹果拒绝?2- 任何人都可以向我提供 Apple 开发人员文档中的相关部分,该部分描述了在 iOS 平台中不允许读取 SMS 消息的部分吗?

采纳答案by rckoenes

  1. No, there is no way to read SMS messages. Apple is very strict on this due to privacy concerns.
  2. Log in to the developers portal and click App Store Review Guidelines.
  1. 不,没有办法阅读短信。由于隐私问题,苹果对此非常严格。
  2. 登录开发者门户并点击App Store Review Guidelines

Nowhere in the guidelines does it specify that you can't access the SMSes. But you can only access then if you use private methods which is not allowed and will get you app rejected.

指南中没有任何地方指定您不能访问 SMSes。但是,如果您使用不允许的私有方法,那么您只能访问,这会使您的应用程序被拒绝。

You can only access data for which Apple supplies a documented API. You can not access file outside of the Sandbox of your App, unless Apple provides an API for it.

您只能访问 Apple 为其提供文档化 API 的数据。您无法访问应用程序沙盒之外的文件,除非 Apple 为其提供 API。

回答by Ashish Kakkad

UPDATE

更新

From iOS 12 Apple has given support to read the security code (OTP - One Time Passwords) in text fields.

从 iOS 12 开始,Apple 支持读取文本字段中的安全代码(OTP - 一次性密码)。

oneTimeCode

Specifies the expectation of a single-factor SMS login code.

一次性代码

指定单因素 SMS 登录代码的期望。

You can autocomplete security codes from single-factor SMS login flows:

您可以从单因素 SMS 登录流中自动完成安全代码:

yourSingleFactorCodeTextField.textContentType = .oneTimeCode

iOS supports Password AutoFill on UITextField, UITextView, and any custom view that adopts the UITextInput protocol.

Warning

If you use a custom input view for a security code input text field, iOS cannot display the necessary AutoFill UI.

iOS 支持 UITextField、UITextView 和任何采用 UITextInput 协议的自定义视图上的密码自动填充。

警告

如果您对安全代码输入文本字段使用自定义输入视图,iOS 将无法显示必要的自动填充 UI。

Security Code Autofill

Security Code Autofill

回答by Ramkrishna Sharma

From iOS 12Apple will supports Password AutoFill on UITextField, UITextView, and any custom view that adopts the UITextInputprotocol. System keyboard set the textContentTypeon it to .oneTimeCode

iOS的12苹果将支持密码自动填充上UITextFieldUITextView和那采用任何自定义视图UITextInputprotocol。系统键盘将其设置textContentType.oneTimeCode

  • Using storyboard/XIB
  • 使用故事板/XIB

Select UITextField/UITextViewin storyboard/XIBclick Click on Attribute inspector. Go to text input trait, click to Content type and select one time code and done.

选择UITextField/UITextViewstoryboard/XIB单击中单击属性检查器。转到文本输入特征,单击内容类型并选择一个时间码并完成。

It only works with System keyboard. So avoid using the custom keyboard.

它仅适用于系统键盘。所以避免使用自定义键盘。


And for more information, you will also review WWDC 2018 Session 204 - Automatic Strong Passwords and Security Code AutoFilland jump to 24:28for automatic pre-fill the OTP.


有关更多信息,您还将查看WWDC 2018 Session 204 - Automatic Strong Passwords and Security Code AutoFill并跳转到24:28以自动预填充 OTP。

iPhoneX image

iPhoneX image

回答by Jamil Hasnine Tamim

For Swift 5:

对于 Swift 5:

From iOS 12Apple has given support to read the security code (OTP - One Time Passwords) in text fields.

iOS 12 开始,Apple 支持读取文本字段中的安全代码(OTP - 一次性密码)。

if #available(iOS 12.0, *) {
               otpField.keyboardType = .default
               otpField.textContentType = .oneTimeCode
       } else {
               // Fallback on earlier versions

       }

Or you can add this contentTypefrom storyboard like below:

或者,您可以从故事板中添加此contentType,如下所示:

enter image description here

enter image description here

回答by Anoop M

Support - Since iOS 12

支持 - 从 iOS 12 开始

Flow, Automatically fill in SMS passcodes on iPhone - https://support.apple.com/en-in/guide/iphone/iphc89a3a3af/13.0/ios/13.0

Flow,在iPhone上自动填写短信密码 - https://support.apple.com/en-in/guide/iphone/iphc89a3a3af/13.0/ios/13.0

Implementation Guide - https://developer.apple.com/documentation/security/password_autofill/enabling_password_autofill_on_a_text_input_view

实施指南 - https://developer.apple.com/documentation/security/password_autofill/enabling_password_autofill_on_a_text_input_view

When you sign in to some apps and websites, a one-time SMS passcode is sent to your iPhone. As a security measure, you are required to enter the code into the app or website. iPhone can detect the passcode in Messages and display it above the keyboard.

To use the passcode, tap it.

当您登录某些应用程序和网站时,一次性短信密码会发送到您的 iPhone。作为一项安全措施,您需要在应用程序或网站中输入代码。iPhone 可以检测信息中的密码并将其显示在键盘上方。

要使用密码,请点按它。

enter image description here

enter image description here