1

I am trying to send sms through device. But it crashes on the line

[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];

Error Log:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <billSummary: 0xfc7e780>.'
Idrees Ashraf
  • 1,363
  • 21
  • 38
  • Have you check picker is nil or not by using breakpoints. According to Error Log it was stating picker was nil to present a modal view so find why picker was nil – Sumanth Jun 29 '12 at 05:28

2 Answers2

2

Have you checked +[MFMessageComposeViewController canSendText]? From the docs,

Before using this class, you must always check to see if the current device is configured to send SMS messages by calling the canSendText class method. If the user’s device is not set up for the delivery of SMS messages, you can notify the user or simply disable the SMS features in your application. You should not attempt to use this interface if the canSendText method returns NO.

Other reasons it might not work:

No SIM card?
Device isn't running iOS 4.
Device is an iPod Touch/iPad.
"Device" is actually the simulator.
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
0
[self presentModalViewController:picker.view animated:YES];

<MFMessageComposeViewControllerDelegate> 

should be added in the .h of your class.

MFMessageComposeViewController is the subclass of UINavatigationController.

so apply pushViewController instead of presentmodalviewController

Pandey_Laxman
  • 3,889
  • 2
  • 21
  • 39