通过Iphone,MFMessageComposeViewController发送短信

时间:2012-06-29 05:25:30

标签: iphone ios mfmailcomposeviewcontroller mfmessagecomposeview

我正在尝试通过设备发送短信。但它在线上崩溃了

[self presentModalViewController:picker animated:YES];

CODE:

MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
        picker.messageComposeDelegate = self;

        picker.recipients = rec; // your recipient number or self for testing
        picker.body = billInfo;

        [self presentModalViewController:picker animated:YES];
        [picker release];

错误日志:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <billSummary: 0xfc7e780>.'

2 个答案:

答案 0 :(得分:2)

您检查过+ [MFMessageComposeViewController canSendText]吗?来自文档,

在使用此类之前,必须始终检查当前设备是否配置为通过调用canSendText类方法发送SMS消息。如果用户的设备未设置为传送SMS消息,则可以通知用户或仅在应用程序中禁用SMS功能。如果canSendText方法返回NO,则不应尝试使用此接口。

其他原因可能无效:

No SIM card?
Device isn't running iOS 4.
Device is an iPod Touch/iPad.
"Device" is actually the simulator.

答案 1 :(得分:0)

[self presentModalViewController:picker.view animated:YES];

<MFMessageComposeViewControllerDelegate> 

应该添加到班级的.h中。

MFMessageComposeViewController是UINavatigationController的子类。

所以应用pushViewController而不是presentmodalviewController