IOS ProgramOfSend SMSCode implementation is the content to be introduced in this article. iOS4.0 has added MFMessageComposeViewController and MFMessageComposeViewControllerDelegate to provideSend SMSYou can send emails without jumping out of the program.Send SMSFor more information, see Message UI Framework Reference.
Notes:
MFMessageComposeViewController
1) provides an operation interface
2) Check the canSendText method before use. If NO is returned, the controller should not be displayed, but the system should prompt that the user does not support sending text messages.
3) the interface cannot be customized.
4) the body and the recipient (recipients) of the text message to be sent must be initialized before the controller is displayed. After the display, the text message content cannot be modified through a program. however, you can manually modify the text message content and select recipients.
5) when the user clicks "send" or "cancel", or fails to send the message, the MFMessageComposeViewControllerDelegate
- – messageComposeViewController:didFinishWithResult:
Methods can be notified, and corresponding processing is performed here
If it runs on iOS3.0, a prompt is displayed.
- dyld: Symbol not found: _OBJC_CLASS_$_MFMessageComposeViewController .
Solution:
1) Select weak for the introduced Type of MessageUI. framework (modify it in target-> Get Info-> General-> Linked Libraries-> MessageUI. framework-> Type)
2) do not directly import MessageUI/MFMessageComposeViewController. h In the. h file, and change it to import <MessageUI/MessageUI. h>
Code:
- # Pragma mark-
- # Pragma mark SMS
- -(IBAction) showSMSPicker :( id) sender {
- // The MFMessageComposeViewController class is only available in iPhone OS 4.0 or later.
- // So, we must verify the existence of the above class and log an error message for devices
- // Running earlier versions of the iPhone OS. Set feedbackMsg if device doesn' t support
- // MFMessageComposeViewController API.
- Class messageClass = (NSClassFromString (@ "MFMessageComposeViewController "));
- If (messageClass! = Nil ){
- // Check whether the current device is configured for sending SMS messages
- If ([messageClass canSendText]) {
- [Self displaySMSComposerSheet];
- }
- Else {
- [UIAlertView quickAlertWithTitle: @ "the device does not have the SMS function" messageTitle: nil dismissTitle: @ "close"];
- }
- }
- Else {
- [UIAlertView quickAlertWithTitle: @ "iOS version is too low. If iOS4.0 or later, you can send a text message" messageTitle: nil dismissTitle: @ "close"];
- }
- }
- -(Void) displaySMSComposerSheet
- {
- MFMessageComposeViewController * picker = [[MFMessageComposeViewController alloc] init];
- Picker. messageComposeDelegate = self;
- NSMutableString * absUrl = [[NSMutableString alloc] initWithString: web. request. URL. absoluteString];
- [AbsUrl replaceOccurrencesOfString: @ "http:// I .aizheke.com" withString: @ "http://m.aizheke.com"
- Options: NSCaseInsensitiveSearch range: NSMakeRange (0, [absUrl length])];
- Picker. body = [NSString stringWithFormat: @ "I have seen on love Guest: % @ may be useful to you. We recommend it to you! Link: % @"
- , [Web stringByEvaluatingJavaScriptFromString: @ "document. title"]
- , AbsUrl];
- [AbsUrl release];
- [Self presentModalViewController: picker animated: YES];
- [Picker release];
- }
- -(Void) messageComposeViewController :( MFMessageComposeViewController *) controller
- DidFinishWithResult :( MessageComposeResult) result {
- Switch (result)
- {
- Case MessageComposeResultCancelled:
- LOG_EXPR (@ "Result: SMS sending canceled ");
- Break;
- Case MessageComposeResultSent:
- LOG_EXPR (@ "Result: SMS sent ");
- Break;
- Case MessageComposeResultFailed:
- [UIAlertView quickAlertWithTitle: @ "failed to send SMS" messageTitle: nil dismissTitle: @ "disabled"];
- Break;
- Default:
- LOG_EXPR (@ "Result: SMS not sent ");
- Break;
- }
- [Self dismissModalViewControllerAnimated: YES];
- }
Summary:IOS ProgramOfSend SMSThe content of code implementation is complete. I hope this article will help you!