2014-02-26 25 views
5

我試圖在我的應用程序中發送電子郵件。我試圖使用MFMailComposeViewController對象,但得到一個錯誤消息說其是「未聲明的標識符」試圖發送電子郵件,「使用未聲明的未識別的MFMailComposeViewController」

代碼:

-(IBAction) aContact: (id) sender; 
{ 


    if([MFMailComposeViewController canSendMail]){ 

     MFMailComposeViewController *mailCtrl = [[[MFMailComposeViewController alloc] init] autorelease]; 
     [mailCtrl setSubject:@"Your TellaFortune Card Reading"]; 
     // [mailCtrl setToRecipients:[NSArray arrayWithObject:@"[email protected]"]]; 
     mailCtrl.mailComposeDelegate = self; 

     NSString *send; 
     send=[ NSString stringWithFormat: @"%@ %@",content,@"\n \n By www.TellaFortune.com"]; 
     [mailCtrl setMessageBody: send isHTML: false]; 

     [self presentModalViewController:mailCtrl animated:NO]; 
     //  [mailCtrl release]; 

    } 
    else 
    { 
     UIAlertView *alert=[[ UIAlertView alloc] 
          initWithTitle:@"Cannot send email" 
          message: @"Please check internet connection and email set up" 
          delegate: self 
          cancelButtonTitle:@"Ok" 
          otherButtonTitles: nil]; 

     [alert show]; 
    } 

} 

回答

13

導入框架「MessageUI.framework」到項目,並在你的.H文件添加

#import <MessageUI/MessageUI.h> 
+0

Thjank你,它的工作原理!!!! –

7

對於誰在使用雨燕,看到這條消息的人:

首先去Xcode中的項目設置,選擇建立階段,然後鏈接二進制文件與庫,並將「MessageUI.framework」添加到您的項目。

然後,在斯威夫特文件中要使用MFMailComposeViewController或實現MFMailComposeViewControllerDelegate,添加:

import MessageUI 
相關問題