2016-06-23 5 views
0

이것은 아주 오래된 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 throws an error only in 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

답변

0

// 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) 
}