2016-07-28 62 views
1

我想從UIAlertController按下按鈕後拉起郵件撰寫視圖控制器。在模擬器中,當我嘗試打開郵件時,我收到了正常的崩潰和錯誤消息,但在應用程序中,我什麼都沒有收到。沒有控制器,沒有崩潰,沒有。這是代碼。郵件撰寫視圖控制器不會從UIAlertController打開

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Email" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 

     [self emailThem]; 

     [self dismissViewControllerAnimated:YES completion:^{ 
     }]; 
    }]]; 

-(void) emailThem { 
    NSLog(@"EMAIL"); 
    MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init]; 
    mail.mailComposeDelegate = self; 
    [mail setSubject:@"To P3 Media"]; 
    [mail setMessageBody:@"Replace this text with your message for all the information you would like on P3 Media." isHTML:NO]; 
    [mail setToRecipients:@[@"[email protected]"]]; 

    [self presentViewController:mail animated:YES completion:NULL]; 
} 

什麼問題?

+0

嘗試把「[自我emailThem]」完成處理的內部駁回視圖控制器之後。還要確保方法emailThem下的presentViewController正在用戶界面線程上運行。 –

+0

@SeanMcDonald好吧,我試過'[self dismissViewControllerAnimated:YES完成:^ {0} {0} {0} {self emailThem; }];但仍然是同樣的事情。 – user717452

+0

你有在設備上設置的電子郵件帳戶嗎? –

回答

0

試試這個代碼

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Email" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 

    [self emailThem]; 

    [self dismissViewControllerAnimated:YES completion:^{ 
    }]; 
}]]; 

-(void) emailThem { 
    NSLog(@"EMAIL"); 
    MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init]; 
    mail.mailComposeDelegate = self; 
    [mail setSubject:@"To P3 Media"]; 
    [mail setMessageBody:@"Replace this text with your message for all the information you would like on P3 Media." isHTML:NO]; 
    [mail setToRecipients:@[@"[email protected]"]]; 
    dispatch_async(dispatch_get_main_queue(),^{ 
     [self presentViewController:mail animated:YES completion:NULL]; 
    }); 
} 
相關問題