gpt4 book ai didi

iphone - MFMailComposeViewController 挂起我的应用程序

转载 作者:行者123 更新时间:2023-12-03 20:29:41 25 4
gpt4 key购买 nike

我正在尝试向我的应用程序添加电子邮件功能。我可以让 MFMailComposeViewController 正确显示并预填充其主题和正文,但由于某种原因,当用户单击导航栏中的“取消”或“发送”按钮时,应用程序只是挂起。我将 NSLog() 语句插入到 mailComposeController"didFinishWithResult:error 的第一行,它甚至没有将该行打印到控制台。

有人知道什么会导致 MFMailComposeViewController 像这样挂起吗?

这是我的标题代码:

#import "ManagedObjectEditor.h"
#import <MessageUI/MessageUI.h>

@interface MyManagedObjectEditor : ManagedObjectEditor
<MFMailComposeViewControllerDelegate, UIImagePickerControllerDelegate,
UINavigationControllerDelegate> {
}

- (IBAction)emailObject;
@end

来自实现文件:

if ([MFMailComposeViewController canSendMail]) {        
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.delegate = self;
[mailComposer setSubject:NSLocalizedString(@"An email from me",
@"An email from me")];
[mailComposer setMessageBody:emailString
isHTML:YES];
[self presentModalViewController:mailComposer animated:YES];
[mailComposer release];
}
[error release];
[emailString release];

这是回调的代码:

#pragma mark -
#pragma mark Mail Compose Delegate Methods
- (void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError *)error {
NSLog(@"in didFinishWithResult:");
switch (result) {
case MFMailComposeResultCancelled:
NSLog(@"cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"saved");
break;
case MFMailComposeResultSent:
NSLog(@"sent");
break;
case MFMailComposeResultFailed: {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error sending email!",@"Error sending email!")
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:NSLocalizedString(@"Bummer",@"Bummer")
otherButtonTitles:nil];
[alert show];
[alert release];
break;
}
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}

谢谢!

最佳答案

我也遇到了这个问题,您需要设置 mailComposeDelegate,而不是委托(delegate)。

关于iphone - MFMailComposeViewController 挂起我的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2428035/

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