I used the sample code on the Apple Dev site to learn how to set pre-composed emails, but is there a way to set precomposed SMS messages, similarly?
First you have to add the framework MessageUI
to your project and import the library "MessageUI/MessageUI.h"
. Then conform to the protocol <MFMessageComposeViewControllerDelegate>
.
Now to send an SMS:
- (IBAction) sendSMS:(id)sender
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = @"The body of the SMS you want";
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
[controller release];
}
To catch the result of the sending operation:
- (void) messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch(result)
{
case MessageComposeResultCancelled: break; //handle cancelled event
case MessageComposeResultFailed: break; //handle failed event
case MessageComposeResultSent: break; //handle sent event
}
[self dismissModalViewControllerAnimated:YES];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With