[英]MFMailComposeViewController not working for me in old iOS code since iOS 9 runtime
这是非常老的iOS4代码,请尝试在iOS9中邮件撰写控制器崩溃时查找错误。
#pragma mark - Export song
- (IBAction)tapExportButton:(id)sender
{
[self dismissAllPopovers];
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
NSString *songDescription = self.songViewController.song.getSongDescription;
[mailer setSubject:[NSString stringWithFormat:@"Chords+Lyrics %@: %@",NSLocalizedString(@"Song", nil),songDescription]];
// Build the attachment. The current song in import/export format.
FileExporter *fileExporter = [[FileExporter alloc]init];
NSData *attachData = [[NSData alloc]init];
if ([fileExporter encodeExportFormat:
[fileExporter songIntoExportFormat:self.songViewController.song]
intoMailAttachment:&attachData]) {
[mailer addAttachmentData:attachData mimeType:@"text/plain" fileName:[NSString stringWithFormat:@"%@.song",songDescription]];
}
NSString *emailBody = [NSString stringWithFormat: NSLocalizedString(@"This song is send to you from the Chords+Lyrics App.", nil) ];
[mailer setMessageBody:emailBody isHTML:NO];
mailer.modalPresentationStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:mailer animated:YES completion: NULL];
[mailer release];
[fileExporter release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
message:@"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
有一些解决方案MFMailComposeViewController仅在iOS 9中引发有关UINavigationBar中的字体问题的错误 ,但这对我不起作用...
日志:
2016-06-23 14:23:59.883 +[NSManagedObjectContext(ActiveRecord) contextWithStoreCoordinator:](5d67a58) Creating MOContext *** On Main Thread ***
2016-06-23 14:23:59.901 -[SongViewController viewDidLoad]: called
2016-06-23 14:24:02.034 viewServiceDidTerminateWithError: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo={Message=Service Connection Interrupted}
2016-06-23 14:24:02.537 -[RootViewController mailComposeController:didFinishWithResult:error:]: Mail cancelled: you cancelled the operation and no email message was queued.
2016-06-23 14:24:02.537 Trying to dismiss the presentation controller while transitioning already. (<_UIFullscreenPresentationController: 0x7fed2a8f4a20>)
2016-06-23 14:24:02.540 transitionViewForCurrentTransition is not set, presentation controller was dismissed during the presentation? (<_UIFullscreenPresentationController: 0x7fed2a8f4a20>)
问候,jr00n
// 1.在“发送”按钮func中编写此代码。
@IBAction func sendEmail(_ sender: Any) {
let mailComposer = MFMailComposeViewController()
if MFMailComposeViewController.canSendMail() {
mailComposer.mailComposeDelegate = self
mailComposer.setToRecipients([emailText.text!])
mailComposer.setSubject(subjectText.text!)
mailComposer.setMessageBody(bodyText.text, isHTML: true)
} else {
print("Mail composer is not able to send Email")
}
}
// 2.实现MFMailComposeViewControllerDelegate协议
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
dismiss(animated: true, completion: nil)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.