2014-09-22 46 views
9

當我運行Xcode 6並使用iOS 8模擬器時,我試圖加載一個MFMailComposeViewController,它沒有出現。相反,我得到這個錯誤...MFMailComposeViewController不顯示在iOS 8中

「警告:試圖提出MFMailComposeViewController:0x7c30c400上的ViewController:0x7baf6000這已經是呈現(空)」

這完全相同的代碼已經工作了將近一年了,不變。 可以肯定的是,我使用iOS 7.1模擬器在Xcode 6中運行我的應用程序,它的工作方式與以前完全一樣。

有誰知道如何在iOS 8中顯示MFMailComposeViewController視圖? 這看起來像一個簡單的任務,我相信它是一個簡單的修復。

PS。不需要發帖,因爲它是標準的代碼,但在這裏它是無論如何...

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 

picker.mailComposeDelegate = self; 

//Current Date 
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
NSDate *date = [NSDate date]; 
//Ensure UTC DATE 
[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; 
[formatter setDateFormat:@"MM/dd/yyyy 'at' HH:mm:ss UTC"]; 
NSString *myString = [formatter stringFromDate:date]; 

NSString *emailBody = [NSString stringWithFormat:@"Feedback time at %@.<br><br>Name:", myString]; 
[picker setMessageBody:emailBody isHTML:YES]; 

NSString *subject, *emailAddress; 

[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; 
[formatter setDateFormat:@"MM/dd/yyyy"]; 
subject = [NSString stringWithFormat:@"Feedback"]; 

//Set the Subject 
[picker setSubject:subject]; 

emailAddress = @"[email protected]"; 

//Set the Receivers 
NSArray *myReceivers = [[NSArray alloc] initWithObjects:emailAddress, nil]; 
[picker setToRecipients:myReceivers]; 

//It saves the file name as the same as Subject here! 
picker.navigationBar.barStyle = UIBarStyleDefault;//UIBarStyleBlack; 
[self presentViewController:picker animated:YES completion:^{}]; 

回答

5

我有一個類似的問題,但沒有得到同樣的消息。但是在iOS 8上我的郵件編輯器不會顯示。我從UIPopover上的一個按鈕啓動它。我會顯示郵件撰寫和代碼,然後幾行後,我叫:

[myPopover dismissPopoverAnimated:YES]; 

在計算器上另一個線程表示,也許有一些東西需要與其他視圖控制器活躍。所以,我提出我的解僱酥料餅的其他呼叫上面顯示郵件撰寫,也使得它沒有設置動畫:

[aboutPopover dismissPopoverAnimated:NO]; 

現在,它的工作原理。

+0

就是這樣。我還從UIPopover上展示了它,並且在打開MailComposer之前添加了該行以解除它,並且它工作正常!謝謝 – Airtower 2014-09-23 02:02:33

-1

這裏是我用來顯示郵件撰寫的代碼,它工作得很好我的版本的Xcode 6.0.1和我的設備(iPhone 5 iOS8上):

-(void) showMailComposer { 
    if(![MFMailComposeViewController canSendMail]) { 
     NSLog(@"Cannot send mail\n%s", __PRETTY_FUNCTION__) ; 
     return ; 
    } 

    // Email Subject 
    NSString *emailTitle = @"Test Email"; 
    // Email Content 
    NSString *messageBody = @"iOS programming is so fun!"; 
    // To address 
    NSArray *toRecipents = [NSArray arrayWithObject:@"[email protected]"]; 

    MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init]; 
    mc.mailComposeDelegate = self; 
    [mc setSubject:emailTitle]; 
    [mc setMessageBody:messageBody isHTML:NO]; 
    [mc setToRecipients:toRecipents]; 

    // Present mail view controller on screen 
    [self presentViewController:mc animated:YES completion:NULL]; 
} 
+0

我試圖複製並粘貼該確切的代碼,並使用它,但我得到確切同樣的錯誤。 – Airtower 2014-09-22 17:27:48

+0

這可能是一個長鏡頭,但是你有最新版本的Xcode嗎? – ElectrikSheep 2014-09-22 17:52:29

0

MFMailComposeViewController不再適用於iOS的8模擬器。

如果你嘗試了物理設備上,你能嘗試只呈現選擇器,沒有任何其他的變化,像這樣:

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
[self presentViewController:picker animated:YES completion:nil]; 

它大概也值得一試什麼[MFMailComposeViewController canSendMail]返回

+0

我沒有在設備上嘗試過它。 – Airtower 2014-09-22 16:19:24

+0

我只是在不同的iPad上試了一遍,沒有運氣 – Airtower 2014-09-22 17:25:38

+0

@Airtower'[MFMailComposeViewController canSendMail]'返回什麼?你有沒有試過運行上面的兩行代碼?你在控制檯輸出中收到任何消息嗎?你有任何崩潰?你在導入MessageUI嗎? '@import MessageUI;' – liamnichols 2014-09-23 08:04:56

1

我不知道爲什麼這個工作。我不是調用此方法之前,但如果我被解僱viewControllers第一它的作品呈現任何其他viewControllers ...

[self dismissViewControllerAnimated:YES completion:^{ 
    [self presentViewController:picker animated:YES completion:^{}]; 
}]; 
+0

這不能解決我的問題。 – andygeers 2014-10-20 11:15:25

+0

這很奇怪!它也適用於我。 – 2014-11-14 22:33:34

0

有同樣的問題,看起來像SDK8.0在iOS8中構建MFMailComposeController作爲popOver,因此您必須關閉任何其他popOver。這是一個它如何工作的例子。

-(void)sendMail{ 
    [[[self fatherController] sharePopOver] dismissPopoverAnimated:YES]; 
    MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init]; 
    [controller setMailComposeDelegate:[self fatherController]]; 
    [[self fatherController] presentViewController:controller animated:YES completion:NULL]; 
} 
+0

這個問題也只發生在iPad上,因爲沒有在iPhone/iPod的彈出 – user2387149 2014-10-13 22:26:16

0

與UIActionSheet有同樣的問題。當UIActionSheet存在時,MFMailComposeViewController不顯示(僅在iOS 8上)。即使你在沒有動畫的情況下解僱它。等待1秒鐘可以解決這個問題。所以我用UIAlertController(在iOS 8中引入)用於新設備,UIActionSheet用於舊設備。我現在有一個醜陋而且很長的代碼,這要歸功於Apple。

+1

嗨,我解決了使用UIActionSheet的問題。我把MFMailComposeViewController顯示在另一個UIActionSheetDelegate回調函數中 - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex'。 – 2015-02-03 09:13:08

0

MailComposer不能在模擬器上工作,但它可以與設備(iOS 8)一起使用。

6

我在iOS 8上有類似的問題,在iOS 7和之前的工作正常。

我在用戶按下UIActionSheet中的按鈕後顯示了我的MFMailComposeViewController。因此,在以前的實現,我把郵件撰寫,並顯示在MFMailComposeViewController功能UIActionSheetDelegate

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 

這是與函數名稱簡單明瞭。

但是,也許是由於某些UI動畫衝突引起的,同時顯示MFMailComposeViewController和解除UIActionSheet使得MFMailComposeViewController未顯示。

  • 解決方案

我的解決辦法是把在UIActionSheetDelegate功能MFMailComposeViewController顯示:

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex 

這是UIActionSheet動畫完成後調用。

希望這可以幫助有同樣問題的人。

+0

此修復程序在iOS 9.2中也適用於我 – 2016-01-28 02:31:07

0

在酥料餅FUNC只是做

@IBAction func exportAsMail(sender: AnyObject) { 

    NSNotificationCenter.defaultCenter().postNotificationName("exportAsMail", object: nil) 

    self.dismissViewControllerAnimated(false, completion: nil) 
    ///****animated have to be false not true 


} 
相關問題