简体   繁体   English

如何检测iOS短信功能(一般不发短信)

[英]How to detect iOS SMS capability (NOT text messaging in general)

I'm writing an app that optionally allows you to send an SMS to a list of users. 我正在编写一个应用程序,可选择允许您将SMS发送到用户列表。 The app currently detects whether the device allows the sending of text messages using MFMessageComposeViewController.canSendText() and only displays the "Send SMS" button when the result is true. 该应用程序当前检测设备是否允许使用MFMessageComposeViewController.canSendText()发送文本消息,并仅在结果为true时显示“发送SMS”按钮。

Today, one of my users complained that when he hit the button on his Wifi-only iPad, nothing happened. 今天,我的一位用户抱怨说,当他点击他的Wifi专用iPad上的按钮时,什么也没发生。 As it turns out, canSendText() also returns true if the iOS device has the iMessage capability turned on, even if SMS is not supported. 事实证明,如果iOS设备启用了iMessage功能,即使不支持SMS,canSendText()也会返回true。 Turning the iMessage capability off in the iOS setting properly disables the "Send SMS" button. 在iOS设置中关闭iMessage功能会禁用“发送短信”按钮。

The problem with sending the message via iMessage is that some recipients will have iMessage turned on and thus will receive the text message. 通过iMe​​ssage发送消息的问题是某些收件人将打开iMessage,因此将收到短信。 But for the recipients without iMessage (it may be turned off or they may not be using an Apple device in the first place), those messages will not arrive. 但是对于没有iMessage的收件人(它可能会被关闭或者他们可能没有首先使用Apple设备),这些邮件将无法到达。 (When the MFMessageComposeViewController eventually comes up, those addresses are marked in red. But my average user is not going to understand that this means the message will not delivered.) (当MFMessageComposeViewController最终出现时,这些地址标记为红色。但我的普通用户不会理解这意味着消息不会被传递。)

Does anybody know of a reliable method that tests for SMS capability specifically, not just for text messages (SMS, iMessage and MMS) in general? 有没有人知道一种可靠的方法来测试SMS功能,特别是对于短信(SMS,iMessage和MMS)?

As far as I know devices with iOS 5+ will return TRUE for MFMessageComposeViewController.canSendText() as they are capable of iMessage 据我所知,iOS 5+的设备将返回TRUE for MFMessageComposeViewController.canSendText()因为它们能够支持iMessage

So I assume you only need to send text if SIM card is installed on device. 因此,我假设您只需要在设备上安装SIM卡时发送文本。 But there is no way to detect if SIM card is installed on device. 但是无法检测设备上是否安装了SIM卡。 Still you can use workaround like : 您仍然可以使用以下方法:

#import<CoreTelephony/CTCallCenter.h>
#import<CoreTelephony/CTCall.h>
#import<CoreTelephony/CTCarrier.h>
#import<CoreTelephony/CTTelephonyNetworkInfo.h>

CTTelephonyNetworkInfo* info = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier* carrier = info.subscriberCellularProvider;
NSString *mobileCountryCode = carrier.mobileCountryCode;
NSString *carrierName = carrier.carrierName;
NSString *isoCountryCode = carrier.isoCountryCode;
NSString *mobileNetworkCode = carrier.mobileNetworkCode;

NSLog(@"\n %@ \n %@ \n %@ \n %@", mobileCountryCode, carrierName, isoCountryCode, mobileNetworkCode);

Here, carrierName will return name when SIM card is present OR last use SIM card info. 这里, carrierName将在SIM卡存在时返回名称或最后使用SIM卡信息。 But others will be null if there is no SIM card installed. 但如果没有安装SIM卡,其他人将为null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM