Mail functionality iphone App Crashes - iphone

While Using email functionality in my App,the App is getting crash if we did'nt sign in at any email address.
Is there anyway to add the exception for this that users gets the Alertview without having App Crash?

What you can do is you can check whether device can send mail or not like below..
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail] == NO) {
//your alertview telling error
return;
}
else
{
//your code for sending mail
}
Happy Coding!#!!!

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;

Is it possible to automatically send SMS's from an iPhone App other than the native text message app?

With the SDK / Cocoa Touch, is it feasible to make an app that will SMS automatically?
My objective isn't to SPAM anyone.
It is not possible, exactly for the reason you mentioned: it would make spamming possible.
You would need a server that would handle the SMS for you, and an API for the app to interact with that server. It's not possible to have your app send messages directly from the phone, but you can certainly have your app interact with an external service that will send the messages for you.
Three is a way to pre-build an SMS using MFMessageComposeViewController. The only issue with this method is that a modal view will be shown to the user to accept the SMS (like the window that sends an e-mail by the default way). There is no way to send a SMS in "silent mode" without jailbreak.
{
...
[self sendSMS:#"_SMS_TEXT_" recipientList:[NSArray arrayWithObjects:#"PHONE_NUMBER", nil]];
...
}
- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = bodyOfMessage;
controller.recipients = recipients;
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissModalViewControllerAnimated:YES];
if (result == MessageComposeResultCancelled)
NSLog(#"Message cancelled")
else if (result == MessageComposeResultSent)
NSLog(#"Message sent")
else
NSLog(#"Message failed")
}

Mail comes Without Message content using MFMailComposeViewController in iPhone

I have faced some problems, when the user sent the mail. Some of the time the mail comes without message content(Email body), even the user typed the message content.The message content doesn't displayed only some times.(For 10 mail comes into my inbox, 2 or 3 messages comes without content in the email body) So please guide me why its happening?
Here my code is,
- (void)viewDidLoad {
[self displayComposerSheet];
}
-(void) displayComposerSheet
{
picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
[picker setToRecipients:[NSArray arrayWithObjects:#"aaa#bbb.com",nil]];
[picker setSubject:#"ShoutOuts"];
}
[self presentModalViewController:picker animated:YES];
}
Please Help me Out.
Thanks!
I don't have a straight answer, but two hints:
a) Why are you calling displayComposerSheet in viewDidLoad? I'd rather put it into viewWillAppear, since the view controller might already be loaded and in memory if used once again.
b) Did you try pre-filling the mail body with a placeholder text to see if that is being sent?

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;

MFMessageComposeViewController alloc returns nil

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.