码迷,mamicode.com
首页 > 其他好文 > 详细

【代码笔记】短信分享

时间:2016-01-27 10:31:29      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

代码:

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.
}
技术分享

 

 

 
 

【代码笔记】短信分享

标签:

原文地址:http://www.cnblogs.com/yang-guang-girl/p/5162209.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!