2016-08-16 47 views
0

目標:實現sharesheet(UIActivityViewController),其中包括Gmail作爲一個選項,並設置收件人和主題設置電子郵件發件人和份額片收件人(IOS)

問題:設置主題的作品,但設置收件人(forKey :「to」)會導致程序崩潰。

我想有能力設置共享表電子郵件客戶端的發件人和收件人字段,但到目前爲止,我一直無法找到任何這樣做的方式。任何幫助表示讚賞!

相關代碼:

let email = ["[email protected]"] 
let activityVC = UIActivityViewController(activityItems: [""], applicationActivities: nil) 

activityVC.excludedActivityTypes = excludedActivity 

activityVC.setValue("Subject Title", forKey: "subject") 

activityVC.setValue(email[0], forKey: "to") 

activityVC.popoverPresentationController?.sourceView = self.view 
self.presentViewController(activityVC, animated: true, completion: nil) 
+0

看到這個問題http://stackoverflow.com/questions/17020288/how-to-set-mail-subject-in-uiactivityviewcontroller-and-also-twitter-sharing-te此外,該文檔UIActivityItemSource HTTPS ://developer.apple.com/library/ios/documentation/UIKit/Reference/UIActivityItemSource_protocol/#//apple_ref/occ/intfm/UIActivityItemSource/activityViewController:subjectForActivityType: – naomimichiko

回答

0

您只能爲UIActivityViewController主題。該程序崩潰,因爲沒有「to」鍵。如果要設置收件人和發件人字段,則必須使用MailMFComposeViewController。

if !MFMailComposeViewController.canSendMail() 
    { 
     let alertMsg = UIAlertController(title: "Test", message: "Mail services not available.", preferredStyle: UIAlertControllerStyle.Alert) 
     alertMsg.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)) 
     self.presentViewController(alertMsg, animated: true, completion: nil) 
    } 
    else 
    { 
     let composeVC = MFMailComposeViewController() 
     composeVC.mailComposeDelegate = self 

     // Configure the fields of the interface. 
     composeVC.setToRecipients(["[email protected]"]) 
     composeVC.setSubject("Subject) 
     composeVC.setMessageBody("Hi.", isHTML: false) 

     // Present the view controller modally. 
     self.presentViewController(composeVC, animated: true, completion: nil) 
    } 
相關問題