Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with MFMailComposeViewController's "No mail accounts" alert - SDK 3.0 vs SDK 4.0

I have a problem with this piece of code when I build it for different Base SDKs:

MFMailComposeViewController *mail = nil;
mail = [[MFMailComposeViewController alloc] init];
NSString *description = @"Some mail string";
if([MFMailComposeViewController canSendMail])
{
    mail.mailComposeDelegate =self;
    [mail setSubject:story.title];
    [mail setMessageBody:[NSString stringWithFormat:(NSString *)kMessageBodyFormat,description,story.webLink] isHTML:NO];
}
[self presentModalViewController:mail animated:YES];
[mail release];
mail=nil;

When I build it with Base SDK 3.0, in case if MFMailComposeViewController's initialization returns nil which occurs if the user does not has any mail accounts, the default "No mail accounts" alert is put up by the system.

But when I build it with Base SDK 4.0 and deploy it for 3.0 OS, if user does not has any mail accounts, the same alert is not displayed by the system, instead presentModalViewController crashes.

MFMailComposeViewController's initialization returns nil if user does not has any mail accounts in both 3.0 and 4.0 base SDK, but somewhere presentModalViewController intelligently puts up the alert in case of SDK 3.0 but SDK 4.0 deployed on 3.0 fails and crashes.

Has anybody faced this problem / any ideas what actually is happening.

Thanks, Raj

like image 531
Raj Pawan Gumdal Avatar asked Dec 08 '22 02:12

Raj Pawan Gumdal


2 Answers

I found this question while I am having the same problem.

I think its because, if there is no mail account set up in the phone. The [[MFMailComposeViewController alloc] init] returns nil.

So before presenting the view controller, we need to check if it is nil or not.

like image 142
karim Avatar answered May 16 '23 09:05

karim


I was just doing some beta testing with iOS 4 and came across your post. I couldn't figure out why it was return nil, so thanks for the answer. As far as an answer to your question, you just need to check if it's nil. If it's nil then don't present the modal view controller. It will still show the popup.

like image 34
brentd49 Avatar answered May 16 '23 08:05

brentd49