iOS 使用MFMailComposeViewController 报错及解决方案
iOS程序崩溃后,控制台显示如下
[MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
[MC] Filtering mail sheet accounts for bundle ID: [MY BUNDLE ID], source account management: 1
[MC] Result: YES
[MC] Reading from public effective user settings.
检查后发现:遵守了协议< MFMailComposeViewControllerDelegate>
设置了代理 mailComposeDelegate,也实现了代理方法
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
if (result == MFMailComposeResultSent)
{
// do something...
}
//关闭邮件发送窗口
[controller dismissViewControllerAnimated:YES completion:nil];
}
然后再次运行,发现还是有如上的报错内容,纠结ing
在网上都查找了各种资料,如:Stackoverflow、CocoaChina、Segmentfault 都没有解决问题。
经过多次尝试得知:
mailComposeDelegate的设置必须是控制器(UIViewController *),否则就会出现如上报错。
好啦,问题解决了 ……
苹果官方文档是这样写的:
@property (nonatomic, assign, nullable) id<MFMailComposeViewControllerDelegate> mailComposeDelegate /*__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0)*/;
这是不是苹果SDK的一个 Bug 呢?!