1. Call the system outside the program to send text messages
This method is actually very simple, just call openURL:
NSURL *url = [NSURL URLWithString:@"sms://15888888888"]; [[UIApplication sharedApplication]openURL:url];
2. Call the system in the program to send text messages
One advantage of this method is that users can return to the App after sending text messages.
First, import and import the header file:
#import <MessageUI/>
Then follow the agentMFMessageComposeViewControllerDelegate
, and implement the proxy method.
#pragma mark - proxy method-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { [self dismissViewControllerAnimated:YES completion:nil]; switch (result) { case MessageComposeResultSent: //The information transmission is successful break; case MessageComposeResultFailed: //Information transmission failed break; case MessageComposeResultCancelled: //The information is cancelled by the user break; default: break; } }
Implementation of SMS
#pragma mark - Send SMS-(void)showMessageView:(NSArray *)phones title:(NSString *)title body:(NSString *)body { if( [MFMessageComposeViewController canSendText] ) { MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init]; = phones; = [UIColor redColor]; = body; = self; [self presentViewController:controller animated:YES completion:nil]; [[[[controller viewControllers] lastObject] navigationItem] setTitle:title];//Change the text interface title } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Prompt message" message:@"This device does not support SMS function" delegate:nil cancelButtonTitle:@"Sure" otherButtonTitles:nil, nil]; [alert show]; } }
Finally, call the method to send the text message
Copy the codeThe code is as follows:
[self showMessageView:[NSArray arrayWithObjects:@"1588888888",@"123999999999", nil] title:@"test" body:@"This is a test text message, do not reply!"];
The above are the two methods of sending text messages by calling the iOS system that the editor introduced to you. I hope it will be helpful to you.