MFMailComposeViewController抛出viewServiceDidTerminateWithError,然后在使用自定义标题字体时退出

gpl*_*cke 36 objective-c ios ios6

我遇到了很长一段时间里遇到的最奇怪的问题......而且我的想法已经用完了.

所以我有一个MFMailComposeViewController,它是通过点击UIButton启动的,它正在启动邮件编辑器视图.你看到我分配的主题,但在to:或body字段填充之前,窗口会闪烁并消失.它抛出此错误:

viewServiceDidTerminateWithError:Error Domain = XPCObjectsErrorDomain Code = 2"无法完成操作.(XPCObjectsErrorDomain error 2.)"

现在这里是疯狂的部分.如果我切换到另一个也使用MFMailComposeViewController的应用程序并启动那个,然后切换回我的应用程序并再次启动邮件编辑器,它工作得很好.我无法解释.

这似乎只是运行iOS 6且不是 iPhone 5的手机的问题.

我四处搜寻,似乎找不到其他人遇到同样的问题.有人有什么建议吗?

我已经将MessageUI.framework链接起来了,我也发现这不能在模拟器或设备上工作,但是当我还链接Security.framework时它开始在模拟器中工作,但它仍然不起作用在设备上.

我的启动MFMailComposeViewController的代码如下:

在.h文件中

#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
Run Code Online (Sandbox Code Playgroud)

在.m文件中

-(void)displayComposerSheet {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

[picker setSubject:@"Support Request"];

// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"support@domain.com"];

[picker setToRecipients:toRecipients];

// Fill out the email body text
NSString *emailBody = @"\n\nEmail from iOS";
[picker setMessageBody:emailBody isHTML:NO];

[self presentModalViewController:picker animated:YES];
}


// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation. 
- (void)mailComposeController:(MFMailComposeViewController*)controller     didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{

    [self dismissModalViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)

更新: 我想我已经将它缩小到我传递给UINavigationBar的外观委托的设置.我使用自定义字体,如果我关闭它似乎工作...但为什么这将在iPhone5上工作...

dbe*_*ick 16

将UITextAttributeFont的自定义字体设置为UINavigationBar外观代理的titleTestAttributes会导致错误,因为OP和MightlyLeader已标识.

解决方法代码:

// remove the custom nav bar font
NSMutableDictionary* navBarTitleAttributes = [[UINavigationBar appearance] titleTextAttributes].mutableCopy;
UIFont* navBarTitleFont = navBarTitleAttributes[UITextAttributeFont];
navBarTitleAttributes[UITextAttributeFont] = [UIFont systemFontOfSize:navBarTitleFont.pointSize];
[[UINavigationBar appearance] setTitleTextAttributes:navBarTitleAttributes];

// set up and present the MFMailComposeViewController
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer setSubject:emailInfo[@"subject"]];
[mailComposer setMessageBody:emailInfo[@"message"] isHTML:YES];
mailComposer.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:mailComposer animated:YES completion:^{

    // add the custom navbar font back
    navBarTitleAttributes[UITextAttributeFont] = navBarTitleFont;
    [[UINavigationBar appearance] setTitleTextAttributes:navBarTitleAttributes];
}];
Run Code Online (Sandbox Code Playgroud)

  • 每次显示邮件编辑器时,您似乎不需要实际来回更改字体设置.不会为`[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class],nil]`设置系统字体一次吗? (3认同)

小智 12

最近这个问题突然出现在我正在研究的项目上.我真的不喜欢上面的解决方法,所以我创建了以下(可能更清洁)的解决方法:

// Implement the custom font for all UINavigationBar items
[[UINavigationBar appearance] setTitleTextAttributes:
@{
    UITextAttributeFont : [UIFont custom_superAwesomeFontWithSize:16.0f],
}];


// Disable the custom font when the NavigationBar is presented in a MFMailComposeViewController
[[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setTitleTextAttributes:
 @{
    UITextAttributeFont : [UIFont boldSystemFontOfSize:14.0f],
 }];
Run Code Online (Sandbox Code Playgroud)


Coc*_*ica 9

我遇到过同样的问题.我已将标题栏的文本属性设置为自定义字体.当我删除自定义字体规范(但将所有其他属性保留为自定义值)时,问题就消失了.

我的诊断是自定义字体加载时间太长,它会触发等待时间超时.


Dav*_*d H 3

将其设为 ivar:

MFMailComposeViewController *picker 
Run Code Online (Sandbox Code Playgroud)

然后在这一行之后:

[self dismissModalViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)

添加这个:

dispatch_async(dispatch_get_main_queue(), ^{ picker = nil; });
Run Code Online (Sandbox Code Playgroud)

这样直到下一个运行循环周期才会释放选择器。