2016-03-03 55 views
-1

我嘗試從我的IOS應用程序發送電子郵件,但它不起作用。我嘗試了很多不同的教程,在真正的iPhone上測試它。我已經實現了MFMailComposeViewControllerDelegate,在h文件中導入了MessageUI/MessageUI.h。郵件打開時,主題在那裏,但不包含郵件本身,也不包含郵件發送給誰(收件人)。兩者都是空的,並且消息不能被髮送。我不明白問題是什麼,我跟着10個不同的教程,但沒有任何作品。我在Xcode 7中工作(目標c)。MFMailComposeViewController只顯示

+0

向我們展示的代碼 – Russell

+0

感謝您迴應,問題是,我不得不重新啓動我的電話。我在這花了7小時:P – mynameiswhat

回答

0

您必須將收件人添加到收件人數組中,並將其傳遞到MFMailComposeViewController。像這樣:

if([MFMailComposeViewController canSendMail]) 
    { 
     MFMailComposeViewController* mail = [[MFMailComposeViewController alloc] init]; 
     [mail setMailComposeDelegate:self]; 
     [mail setSubject:@"Test Subject"]; 
     [mail setMessageBody:@"Stannis Baratheon is the one true King....Also this is a test email" isHTML:NO]; 
     NSArray *arrayOfRecepients = [[NSArray alloc] initWithObjects: @"[email protected]",@"[email protected]",nil];//Add as many email addresses as you want. For single email, add only one email in this array 
     [mail setToRecipients:arrayOfRecepients]; 

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

我假設你沒有正確添加收件人。我正在等待您對羅素評論的迴應,向我們展示您的代碼以正確確定您的代碼出了什麼問題。如有需要,我會更新答案。

0

當我restarded我的手機,它的工作,因此,如果這happends嘗試重新啓動您的iOS設備