views:

77

answers:

1

Hi all,

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

+1  A: 

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.

brentd49
Yes, very true! The crash was due to the nil parameter to presentModalViewController which was alright in 3.0 but in base SDK 4.0 it is problematic. I do not understand one thing though, from where does the "No mail Accounts" alert pops up? Probably the system checks for mail accounts as soon as MFMailComposeViewController's object is spawned and puts up the alert.
Raj