MFMailComposeViewController
我有一个用于通过电子邮件发送文档的应用程序。我在某处读到我需要启用至少一封电子邮件,以便该方法[MFMailComposeViewController canSendEmail]
返回 YES 并通过电子邮件发送文档。但是,每当我点击电子邮件按钮时,它所做的只是返回到上一个视图。
我检查了代码并[MFMailComposeViewController canSendEmail]
返回 NO。谁能告诉我为什么会这样?
这是代码:
- (void)sendEmail
{
if ([MFMailComposeViewController canSendMail] == NO) return;
NSURL *fileURL = document.fileURL; NSString *fileName = document.fileName;
NSData *attachment = [NSData dataWithContentsOfURL:fileURL options:(NSDataReadingMapped|NSDataReadingUncached) error:nil];
if (attachment != nil)
{
MFMailComposeViewController *mailComposer = [MFMailComposeViewController new];
[mailComposer addAttachmentData:attachment mimeType:@"application/pdf" fileName:fileName];
[mailComposer setSubject:fileName];
mailComposer.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
mailComposer.modalPresentationStyle = UIModalPresentationFormSheet;
mailComposer.mailComposeDelegate = self;
[self presentModalViewController:mailComposer animated:YES];
[mailComposer release];
}
}