如何在iOS上以编程方式阅读传入的短信 [英] How to programmatically read incoming text messages on iOS

查看:146
本文介绍了如何在iOS上以编程方式阅读传入的短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于如何以编程方式访问存储在iPhone中的SMS消息,存在很多问题.进行一些小型研究后,您将很快而可悲地发现,由于明显的安全原因,Apple不允许我们的开发人员接触SMS API或SMS数据库.让我们将此事实分开一下.

There have been tons of questions on how to programmatically access the SMS messages stored in the iPhone. Doing a small research you will quickly and sadly find out that Apple won't let us developers touch the SMS API or SMS database due to obvious security reasons. Let's set this fact apart for a moment.

我拥有一辆宝马汽车,配备了称为iDrive的出色信息娱乐"系统.就在最近,我意识到当我的iPhone连接到USB时,我实际上可以通过iDrive系统读取传入的短信.那真的让我很感兴趣.在试用了汽车和电话配置之后,我终于发现iDrive实际上是从通知中心显示文本消息.这意味着,每当我收到一条新消息时,它将在锁定屏幕中显示为通知,并且由于Notification Center具有公共API,因此汽车将能够访问它.从通知中删除消息"应用后,我一无所获.

I own a BMW car that comes equipped with a fantastic "infotainment" system called iDrive. Just recently I realized that I could actually read incoming text messages through the iDrive system when my iPhone is connected to the USB. That really intrigued me. After playing around with the car and the phone configuration, I finally figured out that the iDrive was actually displaying text messages from the Notification Center. This means that every time I get a new message, it would be displayed as a notification in the lock screen and the car would be able to access it because Notification Center has public APIs. As soon as I removed the Messages app from the notification, I got nothing back.

正如许多人以前想过的那样,我还想创建一个应用程序,该程序可以监视传入的文本消息并根据从消息正文中扫描的关键字采取一些措施.

As many of you have thought before, I also wanted to create an app that could monitor incoming text messages and take some action based on keywords scanned from the message body.

直到现在,我真的很愿意转向Android以使我自由,但是,看着汽车上显示传入的短信使我看到隧道尽头的光明.

Until now, I was really inclined toward moving to Android in order to set me free, however, watching the car displaying incoming text messages makes me see some light at the end of the tunnel.

有人知道如何构建可从通知中心读取条目的iOS应用吗?我尝试了一些研究,但这似乎涉及面很广,以至于很难找到有关iOS Notification Center的特定文档.

Does anybody have a clue on how to build an iOS app that can read entries from the Notification Center? I tried some research but this seems to be such a broad matter that it can be difficult to find specific documentation for iOS Notification Center.

我应该提到我不是一位经验丰富的iOS开发人员,因此我们将不胜感激.

I should mention that I am not an experienced iOS developer, so any help will be very appreciated.

顺便说一句-无论如何,我永远无法理解Apple官方文档的支持.有点困惑,无法找到正在运行的应用程序的完整示例.

BTW - I can never understand Apple official documentation support anyway. Kind of confusing to find a complete example of a running app.

感谢您的帮助. 法比奥

Thanks for the help. Fabio

推荐答案

苹果提供了一个读取

in iOS 12 Apple provided an option to read SMS (OTP Password)

如果系统可以从SMS消息中解析安全代码,则 QuickType栏显示后的三分钟内显示代码 已收到.如果在文本输入视图处于打开状态时到达安全码 选择后,系统会将输入的代码推送到QuickType栏.

If the system can parse a security code from an SMS message, the QuickType bar shows the code for up to three minutes after it has been received. If a security code arrives while the text input view is selected, the system pushes the incoming code to the QuickType bar.

要测试不同语言的SMS代码格式,请输入文本 给自己的讯息.如果您收到带有下划线的消息 验证码,请点击验证码.如果出现复制代码"选项,则 系统已识别您的代码.

To test the format of your SMS code for different languages, text a message to yourself. If you receive a message with an underlined security code, tap on the code. If a Copy Code option appears, the system has recognized your code.

iOS在UITextField,UITextView和任何其他版本上支持密码自动填充 采用UITextInput协议的自定义视图.

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

您可以通过单因素SMS登录流程自动完成安全代码

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

以编程方式

yourTextField.textContentType = .oneTimeCode

Storyboard/XIB

在情节提要/XIB中选择UITextField/UITextView,然后单击 属性检查器.转到文本输入特征,单击内容类型",然后 选择一次性代码并完成.

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

在实施之前,请确保

  • 如果您将自定义输入视图用于安全代码输入文本字段, iOS无法显示必要的自动填充UI.
  • 仅适用于系统键盘.因此,请避免使用自定义 键盘.
  • If you use a custom input view for a security code input text field, iOS cannot display the necessary AutoFill UI.
  • It only works with System keyboard. So avoid using the custom keyboard.

这篇关于如何在iOS上以编程方式阅读传入的短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆