gpt4 book ai didi

objective-c - MFMailComposeViewController 抛出 viewServiceDidTerminateWithError 并在使用自定义标题字体时退出

转载 作者:IT老高 更新时间:2023-10-28 11:49:38 27 4
gpt4 key购买 nike

我遇到了很长一段时间以来遇到的最奇怪的问题......而且我已经没有想法了。

所以我有一个 MFMailComposeViewController,它通过点击 UIButton 启动,它启动邮件编写器 View 就好了。您会看到我分配的主题,但在 to: 或 body 字段填充之前,窗口会闪烁并消失。它抛出这个错误:

viewServiceDidTerminateWithError: Error Domain=XPCObjectsErrorDomain Code=2 "The operation couldn't be completed. (XPCObjectsErrorDomain error 2.)"

现在是疯狂的部分。如果我切换到另一个也使用 MFMailComposeViewController 的应用程序并启动该应用程序,然后切换回我的应用程序并再次启动邮件编写器,它就可以正常工作。我无法解释。

这似乎只在运行 iOS 6 且 不是 iPhone 5 的手机上存在问题。

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

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

我的启动 MFMailComposeViewController 的代码如下:

在 .h 文件中

#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>

在 .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];
}

更新:我认为我已将其范围缩小到我已传递给 UINavigationBar 外观委托(delegate)的设置。我有它使用自定义字体,如果我将其关闭,它似乎可以工作......但为什么它会在 iPhone5 上工作......

最佳答案

将 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];
}];

关于objective-c - MFMailComposeViewController 抛出 viewServiceDidTerminateWithError 并在使用自定义标题字体时退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12624151/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com