iOS: Sending SMS

13,319

It's not possible - you have to use MFMessageComposeViewController.

Example of using MFMessageComposeViewController copying your own text in there:

MFMessageComposeViewController *viewController = [[MFMessageComposeViewController alloc] init];
viewController.body = yourTextField.text;
[self presentModalViewController:viewController animated:YES];

where yourTextField is a UITextField or UITextView for user input.

Note you will also want to set the messageComposeDelegate (probably to self) and conform to the MFMessageComposeViewControllerDelegate protocol, in order to know when to dismiss it.

Share:
13,319
Aldee
Author by

Aldee

Web Developer at Arcanys Inc.

Updated on June 25, 2022

Comments

  • Aldee
    Aldee almost 2 years

    Possible Duplicate:
    How to programmatically send SMS on the iPhone?

    Does someone have an idea how to send sms in iOS5 without using the default iPhone/iPad app? I mean in my app, I have a textbox and button. When I hit the button whatever string that the textbox contains will be sent to the specified recipient. Is it possible? thanks,,

  • Aldee
    Aldee about 12 years
    using that object will cause to display the default message app right? my last option is to copy the stringvalue from the textbox in my app and place it in the message box of the default messaging. is it possible?
  • Pangolin
    Pangolin about 12 years
    @Aldee Mativo, That will allow you to send an sms from within your app. You can also programmatically copy the text from your box into that sms.
  • Aldee
    Aldee about 12 years
    @LouwHopley ahh.. thanks.. so really, there's no way to send sms through custom interface other than the default message composer interface right?
  • mattjgalloway
    mattjgalloway about 12 years
    That's right Aldee. I've edited to show example of copying in from a text field / view.
  • Aldee
    Aldee about 12 years
    Now its clear.. thanks LouwHopley...
  • Pangolin
    Pangolin about 12 years
    Yeah, as far as I can recall there is no other way, else you could just send a 1000 sms'e and bankrupt the user or something. Anyways, no problem.
  • Nate Symer
    Nate Symer over 11 years
    I suppose you could set the various fields and then find the method that the "post" button calls and manually call that.
  • mattjgalloway
    mattjgalloway over 11 years
    Sure, but it's likely an undocumented API and so you won't get an app into the App Store that does that.
  • kb920
    kb920 over 9 years
    Working completely just add [viewController setMessageComposeDelegate:self];