MFMailComposeViewController 的“无邮件帐户”问题警报 - SDK 3.0 与 SDK 4.0
当我为不同的 Base SDK 构建这段代码时,我遇到了一个问题:
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;
当我使用 Base SDK 3.0 构建它时,如果 MFMailComposeViewController 的初始化返回 nil,如果用户没有任何邮件帐户,系统默认发出“无邮件帐户”警报。
但是,当我使用 Base SDK 4.0 构建它并将其部署到 3.0 操作系统时,如果用户没有任何邮件帐户,系统不会显示相同的警报,而是 presentModalViewController
崩溃。
如果用户在 3.0 和 4.0 基础 SDK 中都没有任何邮件帐户,则 MFMailComposeViewController 的初始化将返回 nil,但在 SDK 3.0 但 SDK 4.0 的情况下,presentModalViewController
会智能地发出警报在 3.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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当我遇到同样的问题时,我发现了这个问题。
我认为是因为,如果手机中没有设置邮件帐户。
[[MFMailComposeViewController alloc] init]
返回 nil。因此,在呈现视图控制器之前,我们需要检查它是否为零。
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.
我刚刚对 iOS 4 进行了一些 Beta 测试,并看到了你的帖子。我不明白为什么它返回零,所以感谢您的回答。至于你的问题的答案,你只需要检查它是否为零。如果它为零,则不显示模态视图控制器。它仍然会显示弹出窗口。
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.