我有一個應用程序使用MFMailComposeViewController
通過電子郵件發送文檔。我在某處閱讀我需要啓用至少一封電子郵件,以便方法[MFMailComposeViewController canSendEmail]
將返回YES並通過電子郵件發送文檔。然而,只要我點擊電子郵件按鈕,它所做的就是返回到前一個視圖。使用MFMailComposeViewController無法在應用程序中發送電子郵件
我查了代碼,[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];
}
}
喜的委託方法!一旦我嘗試了這個,我會盡快回復你。感謝您的迴應! :) – 2012-08-08 14:20:09
這一個工程。謝謝! – 2012-08-09 02:51:56
提示信息應該是「爲了郵件,請在設置中配置您的電子郵件帳戶。」 – 2015-08-13 07:45:24