MFMailComposeViewController 挂起我的应用程序
我正在尝试向我的应用程序添加电子邮件功能。我可以让 MFMailComposeViewController 正确显示并预填充其主题和正文,但由于某种原因,当用户单击导航栏中的“取消”或“发送”按钮时,应用程序只是挂起。我在 mailComposeController"didFinishWithResult:error
的第一行插入了 NSLog() 语句,它甚至没有将该行打印到控制台。
有谁知道什么会导致 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];
}
!
I am trying to add email functionality to my app. I can get the MFMailComposeViewController to display correctly and pre-populate its subject and body, but for some reason when the user clicks on the "Cancel" or "Send" buttons in the nav bar the app just hangs. I inserted a NSLog() statement into the first line of mailComposeController"didFinishWithResult:error
and it doesn't even print that line out to the console.
Does anybody have an idea what would cause the MFMailComposeViewController to hang like that?
Here is my code from the header:
#import "ManagedObjectEditor.h"
#import <MessageUI/MessageUI.h>
@interface MyManagedObjectEditor : ManagedObjectEditor
<MFMailComposeViewControllerDelegate, UIImagePickerControllerDelegate,
UINavigationControllerDelegate> {
}
- (IBAction)emailObject;
@end
from the implementation file:
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];
and here is the code from the callback:
#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];
}
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也遇到了这个问题,您需要设置 mailComposeDelegate,而不是委托。
I got bit by this too, you need to set the mailComposeDelegate, not the delegate.