2016-08-16 17 views
0

目標:オプションとしてGmailに含まsharesheet(UIActivityViewController)を実装し、受信者と件名(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

UIActivityItemSource httpsのためさらにこの質問http://stackoverflow.com/questions/17020288/how-to-set-mail-subject-in-uiactivityviewcontroller-and-also-twitter-sharing-teマニュアルを参照してください://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) 
    } 
関連する問題