0

我有一個支持iOS 5和iOS 6的應用程序。 MFMailComposeViewController在iOS 6中正常工作,但是當用戶嘗試編輯正文時iOS 5出現崩潰的電子郵件。所有其他領域可以編輯沒有任何問題。 有人看到這個問題嗎?當試圖編輯iOS 5中的電子郵件正文時,MFMailComposeViewController崩潰

的代碼如下:

// Displays an email composition interface inside the application. Populates all the Mail fields. 
-(void)displayMailComposerSheet { 
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
    picker.mailComposeDelegate = self; 

    [picker setSubject:@"xyz"]; 

    NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
    [picker setToRecipients:toRecipients]; 

    [picker setMessageBody:@"xyz" isHTML:NO]; 

    // Deprecated in iOS 6.0: 
    [self presentModalViewController:picker animated:YES]; 
} 

// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the 
// message field with the result of the operation. 
- (void)mailComposeController:(MFMailComposeViewController*)controller 
      didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { 

    // Deprecated in iOS 6.0: 
    [self dismissModalViewControllerAnimated:YES]; 
} 

崩潰日誌如下所示:

Crashed Thread: 0 

Exception Type: EXC_CRASH (SIGABRT) 
Exception Codes: 0x0000000000000000, 0x0000000000000000 

Application Specific Information: 
iPhone Simulator 358.4, iPhone OS 5.1 (iPhone/9B176) 

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MFComposeTextContentView setInputAccessoryView:]: unrecognized selector sent to instance 0x8d6b880' 
*** First throw call stack: 
(0x1da6022 0x1b19cd6 0x1da7cbd 0x1d0ced0 0x1d0ccb2 0x5e4b1 0xb5aa29 0x1d71855 0x1d71778 0xa9f19a 0xaabb03 0x49e084 0x169a798 0x4658fb 0x4675f8 0x45fe29 0x45f133 0x4603bf 0x462a21 0x46297c 0x45b3d7 0x1c01a2 0x1c0532 0x1a6dc4 0x19a634 0x1f39ef5 0x1d7a195 0x1cdeff2 0x1cdd8da 0x1cdcd84 0x1cdcc9b 0x1f387d8 0x1f3888a 0x198626 0x303d 0x2f65) 

abort() called 

Thread 0 Crashed: 
0 libsystem_kernel.dylib   0x99b6e9c6 __pthread_kill + 10 
1 libsystem_c.dylib    0x991a5f78 pthread_kill + 106 
2 libsystem_c.dylib    0x99196bdd abort + 167 
3 libc++abi.dylib     0x027dee78 abort_message + 50 
4 libc++abi.dylib     0x027dc89e _ZL17default_terminatev + 34 
5 libobjc.A.dylib     0x01b19f17 _objc_terminate + 94 
6 libc++abi.dylib     0x027dc8de _ZL19safe_handler_callerPFvvE + 13 
7 libc++abi.dylib     0x027dc946 std::terminate() + 23 
8 libc++abi.dylib     0x027ddb3e __cxa_rethrow + 83 
9 libobjc.A.dylib     0x01b19e15 objc_exception_rethrow + 47 
10 CoreFoundation     0x01cdcde0 CFRunLoopRunSpecific + 304 
11 CoreFoundation     0x01cdcc9b CFRunLoopRunInMode + 123 
12 GraphicsServices    0x01f387d8 GSEventRunModal + 190 
13 GraphicsServices    0x01f3888a GSEventRun + 103 
14 UIKit       0x00198626 UIApplicationMain + 1163 
15 SomeXYZApp      0x0000303d main + 141 (main.m:16) 
16 SomeXYZApp      0x00002f65 start + 53 
+0

只是澄清MFComposeTextContentView是MFMailComposeViewController中的一個對象。實例0x8d6b880的確是MFComposeTextContentView。無論出於何種原因,獲取導致崩潰的選擇器setInputAccessoryView。所有這些都發生在MFMailComposeViewController類的內部。 – Sergio

回答

1

1創建郵件帳戶,如果你嘗試做這個設備

2 MFMailComposeViewController包含methon「canSendMail,所以你可以試試:

if ([MFMailComposeViewController canSendMail]) { 
// create mail 
} else { 
// error message 
} 

3嘗試呼叫控制器在主線程:

dispatch_async(dispatch_get_main_queue(), ^{ 
    //call MFMailComposeViewController 
}); 
+0

步驟1和2已經是我的代碼的一部分。嘗試第3步,但沒有變化。我得到MailCompose視圖,當試圖編輯電子郵件正文時發生崩潰,就好像第一個響應者被髮送到錯誤的對象一樣。 – Sergio

0

再試一次,這可能是你忘了很小的事情......我不知道這生根粉.....你的代碼看起來不錯....它應該工作..

首先添加和導入MessageUI框架

#import <MessageUI/MessageUI.h> 

,並聲明MFMaileComposeViewControllerDelegate

@interface MailViewController : UIViewController <MFMailComposeViewControllerDelegate> 

編寫代碼來發送郵件

- (IBAction)openMail:(id)sender 
{ 
if ([MFMailComposeViewController canSendMail]) 
{ 
    MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init]; 

    mailer.mailComposeDelegate = self; 

    [mailer setSubject:@"xyz"]; 

    NSArray *toRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]; 
    [mailer setToRecipients:toRecipients]; 

    NSString *emailBody = @"xyz"; 

    [mailer setMessageBody:emailBody isHTML:NO]; 

    [self presentModalViewController:mailer animated:YES]; 

    [mailer 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]; 
} 

}

,也寫MFMailComposeViewControllerDelegate

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 
    switch (result) 
    { 
     case MFMailComposeResultCancelled: 
      NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued."); 
      break; 
     case MFMailComposeResultSaved: 
      NSLog(@"Mail saved: you saved the email message in the drafts folder."); 
      break; 
     case MFMailComposeResultSent: 
      NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send."); 
      break; 
     case MFMailComposeResultFailed: 
      NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error."); 
      break; 
     default: 
      NSLog(@"Mail not sent."); 
      break; 
    } 

     // Remove the mail view 
    [self dismissModalViewControllerAnimated:YES]; 
} 
+0

不是。這基本上就是我所擁有的。正如我之前提到的,我顯示了MailComposer視圖。所以所有的制衡都已完成。除了電子郵件的正文外,我可以點擊視圖中的所有條目。如果身體不變,我甚至可以發送電子郵件。只有在試圖編輯身體時,應用程序崩潰,並且這種情況只發生在運行iOS 5的設備上。 – Sergio

+0

在您的電子郵件正文中.......您在展示什麼........?它是HTML還是簡單文本....? – Wolverine

+0

你在使用ARC ..嗎? – Wolverine

0

的委託方法我已經找到了問題。我正在使用允許滾動解除鍵盤的DAKeyboardControl(請參閱GitHub for DA's KeyboardControl)。

當通過MFMailComposeViewController調用DA代碼中的responderDidBecomeActive時,textField會收到一個不響應inputAccessoryView的MFComposeTextContentView對象。這似乎是一種不被支持的互動。但是請注意,在iOS 6中,這個問題不會發生,因爲DA的重載類不會被MFMailComposeViewController調用。

如果DAKeyboardControl支持被刪除,一切正常。

+0

Daniel的代碼的最新版本修復了這個問題。謝謝丹尼爾! – Sergio

1

有同樣的問題。只在IOS6中,而不在IOS5.1中。測試瞭解到表單沒有正確釋放。因此我添加了代碼來強制發佈表單。這對我來說很合適。希望它也能幫助你。

-(void) sendMail:(NSString *) mailTo 
{ 
    // Check if you can send an e-mail 
    if ([MFMailComposeViewController canSendMail]) 
    { 
     @try 
     { 
      // show the form 
      MFMailComposeViewController *mailForm = nil; 
      mailForm = [[MFMailComposeViewController alloc] init]; 
      mailForm.mailComposeDelegate = self; 
      [mailForm setToRecipients:@[ mailTo ]]; 
      mailForm.modalPresentationStyle = UIModalPresentationFormSheet; 
      mailForm.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
      [self presentModalViewController:mailForm animated:YES]; 
     } 

     @catch (NSException *exception) 
     { 
      // Show what went wrong 
      NSString *fout = [[NSString alloc] initWithFormat:@"%@: %@",[exception name], [exception reason]]; 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Mailer" message:fout delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      [alert show]; 
     } 
    } 
    else 
    { 
     // Inform the user you cannot send mail, no mailbox set 
     [self noEmailAccountMeansNoEmail]; 
    } 
} 

- (void)mailComposeController:(MFMailComposeViewController*)mailForm didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 
    // Get the mail form off the screen 
    if ((mailForm != nil)) 
     [mailForm dismissModalViewControllerAnimated:YES]; 

    // Force release/dealloc of the screen 
    mailForm = nil; 
    return; 
} 
相關問題