短信通过Iphone,MFMessageComposeViewController



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

[self presentModalViewController:picker animated:YES];

法典:

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>.'

你有没有检查过+[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.
[self presentModalViewController:picker.view animated:YES];
<MFMessageComposeViewControllerDelegate> 

应该添加到您类的 .h 中。

MFMessageComposeViewController 是 UINavatigationController 的子类。

所以应用 pushViewController 而不是 presentmodalviewController

相关内容

  • 没有找到相关文章

最新更新