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

调用iPhone的短信

时间:2014-11-15 16:46:33      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   os   sp   div   

 

不传递短信内容,可以调用下面的方法:

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://466453"]];//sms://电话号码

 

下面的方法会传递欲发送短信的内容

- (IBAction)sendSMSAction:(id)sender {
    
    [self sendSMS:@"hahahahahha" recipientList:@[@"133..."]];//recipientList:短信接收人的电话号码数组
}

- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
    MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
    if([MFMessageComposeViewController canSendText])
    {
        controller.body = bodyOfMessage;
        controller.recipients = recipients;
        controller.messageComposeDelegate = self;
//        [self presentModalViewController:controller animated:YES];
        [self presentViewController:controller animated:YES completion:nil];
    }
}

// 处理发送完的响应结果
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [self dismissViewControllerAnimated:YES completion:nil];
    
    if (result == MessageComposeResultCancelled) {
        NSLog(@"message cancelled");
    }
    else if (result == MessageComposeResultSent) {
        NSLog(@"message sent");
    }
    else {
        NSLog(@"message failed");
    }

}

原文:http://blog.csdn.net/hopedark/article/details/7970421

调用iPhone的短信

标签:style   blog   http   io   color   ar   os   sp   div   

原文地址:http://www.cnblogs.com/benbenzhu/p/4099384.html

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