2016-08-23 27 views
2

MFMailComposeViewControllerを使用して電子メールを送信していますが、電子メールを送信した後で電子メールと時刻をテーブルビューで表示します。どうやってやるの?送信された電子メールから送信された電子メールとタイムスタンプをテーブルビューに保存

私のテーブルのコードは基本的なものです

//This is empty, just to populate the empty table for now 
var sentEmails = [String]() 

//Number of Sections 
func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    return 1 
} 

//Number of Rows 
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return sentEmails.count 
} 

//Cell Configuration 
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) 

    let row = indexPath.row 
    cell.textLabel?.text = sentEmails[row] //Email here? 
    cell.detailTextLabel?.text = "time stamp"//maybe? 

    return cell 
} 

このメールに対する私のコードです

func contactPicker(picker: CNContactPickerViewController, didSelectContactProperty contactProperty: CNContactProperty) { 

    //Checks if composer can sent email 
    if MFMailComposeViewController.canSendMail() { 

     let mail = MFMailComposeViewController() 

     mail.mailComposeDelegate = self 

     //Add the email to the recipient field 
     if let emailAddress = contactProperty.value as? String { 
      mail.setToRecipients([emailAddress]) 
     } 

     //Dismisses the current view and presents the mail composer view 
     self.dismissViewControllerAnimated(true, completion: {() -> Void in 
      self.presentViewController(mail, animated: true, completion: nil) 
     }) 

    } else { 
     print("send error") 
    } 
} 

//Dismiss Buttons for Mail Composer 
func mailComposeController(controller:MFMailComposeViewController, didFinishWithResult result:MFMailComposeResult, error:NSError?) { 

    switch result { 
    case MFMailComposeResultCancelled: 
     print("Mail Cancelled") 
    case MFMailComposeResultSaved: 
     print("Mail Saved") 
    case MFMailComposeResultSent: 
     print("Mail Sent") 
    case MFMailComposeResultFailed: 
     print("Mail sent failure: \(error)") 
    default: 
     break 
    } 

    controller.dismissViewControllerAnimated(true, completion: nil) 
} 

は、どのように私は私のテーブルの上に表示するために送信される電子メールや時間を得ることができますか?前もって感謝します。

答えて

0

MFMailComposeViewControllerは処理が終了し、完了ステータス以外の情報はこれ以上提供されません。

さらに詳しい情報が必要な場合は、電子メールを手動で送信する必要があります。これは、製品の中核でない限り、私が強く推奨する非常に退屈な作業です。

更新組み込みのメールコンポーザーを使用して取得することはできません。電子メールクライアントを再導入したい場合は、いくつかのオープンソースクライアントがあります:http://libmailcore.com; (ユーザーアカウントにアクセスせずに、最初からアカウントを設定することを忘れないでください)。代わりに、サーバーやサードパーティのサービスからクライアントにUIのみを提供する電子メールを実装することもできます。サードパーティのサービスhttps://github.com/sendgrid/sendgrid-objc

+0

私は送信した時間と電子メールをどのように受け取るのですか?私はこの情報しか必要としませんでした。私はすぐに新しいですので、私はそれがどのくらい動作するかはあまり知られていません。 – art3mis

+0

私の回答 –

+0

への更新を見てください更新していただきありがとうございます。あなたはちょうど私にアイデアをくれました。完了エリアでは、ちょうど使用した電子メールと現在のNSDateを送信して、それを配列に送信することができます。どのようにそれを行うかわからないが、良いアイデアのように聞こえる。 – art3mis

関連する問題