1

我试图通过设备发送短信。但它崩溃就行通过Iphone,MFMessageComposeViewController发送短信

[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>.' 
+0

你有没有检查选择器是使用断点零与否。根据错误日志它声明选择器是零为呈现模式视图,所以找到为什么选择器是零 – Sumanth

回答

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. 
+0

谢谢,我正在测试ipod。很好的指导 –

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

<MFMessageComposeViewControllerDelegate> 

应该在类的.H添加。

MFMessageComposeViewController是UINavatigationController的子类。

所以适用pushViewController代替presentmodalviewController

+0

通过传递picker.view它提供了不兼容的指针类型警告。 –