1

デバイスを介してSMSを送信しようとしています。しかし、それはライン上でクラッシュします

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

2 に答える 2

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.
于 2012-06-29T05:34:31.177 に答える
0
[self presentModalViewController:picker.view animated:YES];

<MFMessageComposeViewControllerDelegate> 

クラスの .h に追加する必要があります。

MFMessageComposeViewController は UINavatigationController のサブクラスです。

したがって、presentmodalviewController の代わりに pushViewController を適用します

于 2012-06-29T05:30:41.127 に答える