MFMessageComposeViewController alloc returns nil - iphone

In my application, MFMailComposeViewController works fine but creating a new instance of MFMessageComposeViewController fails.
Here is the code for both:
-( IBAction)sendSMS: (id)sender
{
MFMessageComposeViewController *picker = [[[MFMessageComposeViewController alloc] init] autorelease];
picker.messageComposeDelegate = self;
NSArray *toRecipients = [NSArray arrayWithObject: cell.currentTitle ];
picker.recipients = toRecipients;
[self presentModalViewController:picker animated:YES];
}
-( IBAction)sendEmail: (id)sender
{
MFMailComposeViewController *picker = [[[MFMailComposeViewController alloc] init] autorelease];
picker.mailComposeDelegate = self;
NSArray *toRecipients = [NSArray arrayWithObject: email.currentTitle ];
[picker setToRecipients:toRecipients];
[self presentModalViewController:picker animated:YES];
}
Its seemingly obvious that everything is linking correctly because the email view controller works fine. Is there something I am missing maybe configuration wise?

Have you checked +[MFMessageComposeViewController canSendText]?
From the MFMessageComposeViewController Class Reference,
Before presenting a message composition view, call the canSendText class method to ensure that the user’s device is appropriately configured. Do not attempt to present a message composition view if the canSendText method returns NO. If SMS delivery isn’t available, you can notify the user or simply disable the SMS features in your application.
Starting in iOS 5, you can register to be notified of changes to the availability of text message sending by way of the MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification notification.
Reasons it might be returning nil:
Device isn't running iOS 4.
Device is an iPod Touch/iPad without iMessage enabled.
No SIM card? (The view now shows in iOS 6; the app is not notified of the message send failure.)
"Device" is actually the simulator. (Perhaps this works in iOS 6 too.)
Similarly, [[MFMailComposeViewController alloc] init] returns nil when no mail accounts are enabled (you can quickly test this by disabling accounts in Settings), but also shows a "No mail accounts configured" alert for you. MFMessageComposeViewController does not do this.

Related

MFMessageComposeViewController stops sms messaging

I'm using MFMessageComposeViewController in my iOS app.
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText]){
controller.body = text;
controller.recipients = [NSArray arrayWithObjects:recipient,nil];
controller.messageComposeDelegate = self.navigationController;
[self.navigationController presentViewController:controller animated:YES];
}
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
[self dismissModalViewControllerAnimated:YES];
}
Button "send message" is blue. If you send message not to the iMessage user, iPhone send sms not iMessage, but on some devices(iPhone 4, 5) operation fails. After that error you can't send messages to the user at all !!! using standard sms application in iPhone.
Deletion of contact, reboot, switching off iMessage doesn't solve this problem. MFMessageComposeViewController kills sms sending and we can't solve this issue.
We have iOS 6.1.3 version on out test devices.
try
controller.messageComposeDelegate = self;

Sending an email through app; any way will do

Here is the code that I have for my cell of my UITableView:
forKeys:[NSArray arrayWithObjects:#"Title", #"Cells", #"Footer Title", nil]] autorelease];
[tableView1CellData addObject:sectionContainer_3];
NSMutableArray *cells_4 = [[[NSMutableArray alloc] init] autorelease];
NSDictionary *cellContainer_4_1 = [[[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:#"Support", #"", #"", #"", #"", #"1", nil]
What would I have to add so that when the cell is tapped, it happened up a MailView in the app (preferably) but I understand that the easiest way is to just use the HTML "mailto" ? I'm brand new to Objective-C, but I am able to edit C and C++, so I think that I can work in any answer. Thanks in advance!
P.S. Posting this from iPhone (just thought of asking question) so sorry if the code isn't highlighted, but i tried to space it out.
Check out the documentation on MFMailComposeViewController. You can present a mail compose view, user will fill it out and send the mail.
1.Add the Message UI Framework
2.You should have registered a delegate for the UITableView. See a UITableView tutorial if needed.
3.Implement the following method:
- (void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
...
}
4.Inside the method use MFMailComposeViewController to send the email. Example usage:
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:#"My Subject"];
[controller setMessageBody:#"Hello there." isHTML:NO];
if (controller) [self presentModalViewController:controller animated:YES];
[controller release];
Read More: How can I send mail from an iPhone application
UITableView/UITableViewCell tap event response?
And yes, you can use the mailto: URL thing... but #jer's answer is the one I would prefer to do myself, as a developer.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"mailto://info#iosdevelopertips.com"]];
(details for the above can be found at http://iosdevelopertips.com/cocoa/launching-other-apps-within-an-iphone-application.html)

Problem MFMessageComposerViewController in iPhone sdk

I am trying to implement a SMS application. In that when I tried to send my sms I got an exception at [self.navigationController presentModalViewController:picker animated:YES];. I am very new to this. Can you guys please help me?. My code is as follows.
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.delegate = self;
picker.recipients = [NSArray arrayWithObject:#"123456789"]; // your recipient number or self for testing
picker.body = #"test from OS4";
[self.navigationController presentModalViewController:picker animated:YES];
[picker release];
My Log message is as follows,
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <UINavigationController: 0x5b2c120>.
Thanks in Advance,
S.
The message means picker is nil, i.e. the MFMessageComposeViewController is not created successfully.
Make sure [MFMessageComposeViewController canSendText] returns YES, i.e..
if (![MFMessageComposeViewController canSendText]) {
// show message box for user that SMS cannot be sent
} else {
MFMessageComposeViewController* picker = ...;
...
}
Most probably you are testing this in your iPhone simulator, MFMessageComposeViewController does not work on a simulator and returns nil
Three things come to mind.
First, have you declared your view controller class to be implement MFMailComposeViewControllerDelegate? And have you defined mailComposeController:didFinishWithResult:error: ?
Second, you could just have: [self presentModalViewController:picker animated:YES];
Third, are you sure that picker is non-nil?
The main reason that the modal view will throw a nil exception usually has to do with the device under test not having an email account configured in settings (hence the other comment about the modal view not working in the simulator). #KennyTM's answer is a great way to handle this. Just popup an alert dialog notifying the user.

Iphone 4 MFmailcompose viewcontroller crash

Iphone 4 MFMailComposeViewController
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setMessageBody:#"Welcome" isHTML:NO];
[controller release];
My app to be crash.
Wat i did wrong
Regards,
Arun
The mail composer will crash if the user is unable to send mail. First check to see if the user is able to send mail before trying to instantiate a MFMailComposeViewController.
if([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController* controller = [[[MFMailComposeViewController alloc] init] autorelease];
//...
}
#Arun , First up all configure the email settings in your device
As Akira says, you can use MFMailComposeViewController after you set up the device's e-mail settings.
init failed, because not iOS mail-application's setting.
MFMailComposeViewController* controller = [[[MFMailComposeViewController alloc] init] autorelease];
if (!controller) // failed
return; // auto view alert, "not mail setting..."
controller.mailComposeDelegate = self;

Sending sms programmatically code Problem

I am writing code to send sms programatically
Program crashes at second last line.
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
picker.recipients = [NSArray arrayWithObject:#"123456789"]; // your recipient number or self for testing
picker.body = #"test from OS4";
[self presentModalViewController:picker animated:YES];
[picker release];
I assume it's safe to say that it implements
UIViewController <MFMessageComposeViewControllerDelegate>
In which case, I would recommend going back to http://iphonesdkdev.blogspot.com/2010/04/mfmessagecomposeviewcontroller-sample.html, copying their example and progressing from there.