IPhone SMS Features

I use the following code in my application to create and populate SMS to send to the user. This code is called by pressing UIButton.

MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease]; if([MFMessageComposeViewController canSendText]) { controller.body = @"Hello from Mugunth"; controller.recipients = [NSArray arrayWithObjects:@"12345678", @"87654321", nil]; controller.messageComposeDelegate = self; [self presentModalViewController:controller animated:YES]; } 

When I first load the view, I would like to check the capabilities of the device and, if necessary, hide the button (for example, on iPod touch).

Does anyone have code examples on how to do this? Please note that I focus only on iOS 4.0 and higher, I know that the above code will not work on devices using earlier versions of iOS.

Hello

+4
source share
3 answers

[MFMessageComposeViewController canSendText] will determine if your device can send text messages. I knew that it responds correctly to an iPhone with a SIM card, iPod Touch and iOS Simulator. I have not tested it, for example. iPhone without a SIM card or iPad.

+4
source

You can use the code below to determine if the device can send an SMS message or not:

Preferred:

 if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"sms:"]]) { } 

or

 [MFMessageComposeViewController canSendText] 
+2
source

Before distributing an instance of MFMessageComposeViewController make sure you call [MFMessageComposeViewController canSendText] . Newer versions of iOS will trigger a warning informing the user that they cannot send messages as soon as you create an instance of MFMessageComposeViewController.

0
source

Source: https://habr.com/ru/post/1342458/


All Articles