代碼:ViewController.h#import //簡訊分享#import #import @interface ViewController : [email protected]#import "ViewController.h"@interface ...
代碼:
ViewController.h
#import <UIKit/UIKit.h>
//簡訊分享
#import <MessageUI/MFMailComposeViewController.h>
#import <MessageUI/MFMessageComposeViewController.h>
@interface ViewController : UIViewController<MFMessageComposeViewControllerDelegate>
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
//點擊任何處,簡訊分享
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//調用系統發送信息功能
BOOL canSendSMS = [MFMessageComposeViewController canSendText];
if (canSendSMS) {
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
NSArray *array = [[NSArray alloc] initWithObjects:nil];
picker.recipients=array;
picker.view.frame=CGRectMake(0, 0, 320, 640);
[self presentViewController:picker animated:YES completion:nil];
}else{
UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@""
message:@"當前設備不支持簡訊功能"
delegate:nil
cancelButtonTitle:@"確定"
otherButtonTitles:nil];
[alert show];
}
}
#pragma -mark -系統消息回調
//系統發送信息的回調函數
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
//[self dismissModalViewControllerAnimated:YES];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}