调用iPhone的短信

 

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

    [[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

posted @ 2014-11-15 15:34  Dadada胖纸er  阅读(177)  评论(1编辑  收藏  举报