调用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

你可能感兴趣的:(iPhone)