Two ways to send SMS to IOS call system _ios

Source: Internet
Author: User

One, the program outward use system text message

This method is actually very simple, direct call OpenURL can:

Nsurl *url = [Nsurl urlwithstring:@ "sms://15888888888"];
[[UIApplication Sharedapplication]openurl:url];

Second, the program calls the system to send text messages

One advantage of this approach is that users can return to the app after texting.

First you import the messageui.framework and introduce the header file:

#import <MessageUI/MessageUI.h>

Then you follow the agent and MFMessageComposeViewControllerDelegate implement the proxy method.

#pragma mark-Proxy method
-(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *) controller Didfinishwithresult: (messagecomposeresult) result
{
  [self dismissviewcontrolleranimated:yes completion: NIL];
  Switch (Result) {case
    messagecomposeresultsent:
      //Information transmission successful break
       
      ;
    Case messagecomposeresultfailed:
      //Information transmission failed break
       
      ;
    Case messagecomposeresultcancelled:
      //Information cancelled by the user transmission break
       
      ;
    Default: Break
      ;
  }
}

Send SMS method to achieve

#pragma mark-Send SMS Method
-(void) Showmessageview: (Nsarray *) phones title: (NSString *) title: (NSString *) body
{
  if ([Mfmessagecomposeviewcontroller Cansendtext])
  {
    Mfmessagecomposeviewcontroller * controller = [[Mfmessagecomposeviewcontroller alloc] init];
    controller.recipients = phones;
    Controller.navigationBar.tintColor = [Uicolor redcolor];
    Controller.body = body;
    Controller.messagecomposedelegate = self;
    [Self Presentviewcontroller:controller animated:yes completion:nil];
    [[[[[[[[[Controller viewcontrollers] lastobject] navigationitem] settitle:title];//Modify SMS interface title
  }
  else
  {
    Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "prompt info"
                            message:@ "This device does not support SMS features"
                            Delegate:nil
                       cancelbuttontitle:@ "Determine"
                       otherbuttontitles:nil, nil];
    [Alert show];
  }

Finally, the method of sending a text message is called

Copy Code code as follows:

[Self Showmessageview:[nsarray arraywithobjects:@ "15888888888", @ "12399999999", Nil] title:@ "test" body:@ "This is a test message, Don't reply! "];

The above is a small series of iOS to introduce the system to send text messages to the two methods, I hope to help.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.