2016-09-05 70 views
3

我是新來這個,MailCompositionService意外退出IOS

我在我的viewController這段代碼,

- (void)sendMail:(id)sender { 
    NSArray *to = [NSArray arrayWithObjects:@"[email protected]", nil]; 

    mailComposer = [[MFMailComposeViewController alloc] init]; 
    mailComposer.mailComposeDelegate = self; 
    [mailComposer setToRecipients:to]; 
    [mailComposer setSubject:@"Test Mail"]; 
    [mailComposer setMessageBody:@"Testing message body" isHTML:NO]; 
    [self presentModalViewController:mailComposer animated:YES]; 
} 



#pragma mark - mail compose delegate 
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { 
    if(result) { 
     NSLog(@"Result = %d", result); 
    } 
    if(error) { 
     NSLog(@"Error = %@", error); 
    } 
    [self dismissModalViewControllerAnimated:YES]; 
} 

但是,當我在我的控制器點擊發送按鈕,我得到的錯誤一樣,

2016-09-05 14:55:24.488 mailDemo[1276:104171] viewServiceDidTerminateWithError: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo={Message=Service Connection Interrupted} 2016-09-05 14:55:24.989 mailDemo[1276:104171] Trying to dismiss the presentation controller while transitioning already. (<_UIFullscreenPresentationController: 0x7fe35b52d2a0>) 2016-09-05 14:55:24.991 mailDemo[1276:104171] transitionViewForCurrentTransition is not set, presentation controller was dismissed during the presentation? (<_UIFullscreenPresentationController: 0x7fe35b52d2a0>)

問題是什麼?

+0

請在設置應用程序中檢查您的設備登錄郵件。 –

+0

檢查後是否可以呈現郵件撰寫控制器,然後在設備中使用郵件配置進行測試。 –

+0

我正在模擬器中測試它。 @BhadreshKathiriya – KAR

回答

2

你的代碼沒有問題。 MFMailComposeViewController不適用於模擬器,請在實際設備中嘗試相同的代碼。

+0

謝謝,我認爲MFMailComposeViewController不能在模擬器中工作。 @ajay_nasa – KAR

+0

不用擔心,快樂編碼。 –

1

模擬器不支持方法和設備不在郵件登錄,這種方法沒有任何反應。

替換此方法::

- (void)sendMail:(id)sender { 


    if (![MFMailComposeViewController canSendMail]) { 
     NSLog(@"Mail services are not available."); 
     return; 
    } 
    else{ 
      NSArray *to = [NSArray arrayWithObjects:@"[email protected]", nil]; 

      mailComposer = [[MFMailComposeViewController alloc] init]; 
      mailComposer.mailComposeDelegate = self; 
      [mailComposer setToRecipients:to]; 
      [mailComposer setSubject:@"Test Mail"]; 
      [mailComposer setMessageBody:@"Testing message body" isHTML:NO]; 
      [self presentModalViewController:mailComposer animated:YES]; 
     } 
} 
0

MFMailComposeViewController不適用於模擬器工作。如果你在真實設備上嘗試相同的代碼,它將會起作用。你的代碼沒有問題。