質問編集履歴

3

コメント追加

2019/01/08 05:15

投稿

TakamasaIijima
TakamasaIijima

スコア16

test CHANGED
File without changes
test CHANGED
@@ -118,7 +118,7 @@
118
118
 
119
119
 
120
120
 
121
- ## 回答をいただいた後に編集しました。
121
+ ## 回答をいただいた後に編集しました。(回答箇所は未編集)
122
122
 
123
123
  ```swift
124
124
 

2

ViewControllerを追加

2019/01/08 05:14

投稿

TakamasaIijima
TakamasaIijima

スコア16

test CHANGED
File without changes
test CHANGED
@@ -115,3 +115,83 @@
115
115
  Xcode Version 10.1 (10B61)
116
116
 
117
117
  Swift3
118
+
119
+
120
+
121
+ ## 回答をいただいた後に編集しました。
122
+
123
+ ```swift
124
+
125
+
126
+
127
+ var mailViewController = MFMailComposeViewController()
128
+
129
+ let currentViewController : UIViewController? = UIApplication.shared.keyWindow?.rootViewController! //<=追記
130
+
131
+ @IBAction func sendMail() {
132
+
133
+ //メールを送信できるかチェック
134
+
135
+ if MFMailComposeViewController.canSendMail()==false {
136
+
137
+ print("Email Send Failed")
138
+
139
+ return
140
+
141
+ }
142
+
143
+
144
+
145
+ var mailViewController = MFMailComposeViewController()
146
+
147
+ var toRecipients = ["XXXX@gmail.sampledomainX"]
148
+
149
+
150
+
151
+ mailViewController.mailComposeDelegate = self
152
+
153
+ mailViewController.setSubject("メールの件名")
154
+
155
+ mailViewController.setToRecipients(toRecipients) //Toアドレスの表示
156
+
157
+ mailViewController.setMessageBody("メールの本文", isHTML: false)
158
+
159
+ //var currentViewController : UIViewController? = UIApplication.shared.keyWindow?.rootViewController!
160
+
161
+ currentViewController?.present(mailViewController, animated: true, completion: nil)
162
+
163
+ }
164
+
165
+
166
+
167
+ func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
168
+
169
+ if result == MFMailComposeResult.cancelled {
170
+
171
+ print("メール送信がキャンセルされました")
172
+
173
+ } else if result == MFMailComposeResult.saved {
174
+
175
+ print("下書きとして保存されました")
176
+
177
+ } else if result == MFMailComposeResult.sent {
178
+
179
+ print("メール送信に成功しました")
180
+
181
+ } else if result == MFMailComposeResult.failed {
182
+
183
+ print("メール送信に失敗しました")
184
+
185
+ }
186
+
187
+
188
+
189
+ currentViewController?.dismiss(animated: true, completion: nil)
190
+
191
+
192
+
193
+ //mailViewController.dismiss(animated: true, completion: nil) //閉じる <= Controllerを間違えていたので編集
194
+
195
+ }
196
+
197
+ ```

1

タイトル名を変更 フレームワーク名追加

2019/01/08 05:14

投稿

TakamasaIijima
TakamasaIijima

スコア16

test CHANGED
@@ -1 +1 @@
1
- Swift SpriteKit上でmail作成画面が閉じれない
1
+ Swift SpriteKit上でMFMailComposeViewControllerで作成したmail作成画面が閉じれない
test CHANGED
@@ -1,6 +1,8 @@
1
1
  ### 前提・実現したいこと
2
2
 
3
3
  Swift+SpriteKitで2Dのゲームを作っています。
4
+
5
+ MessageUI.frameworkを使って
4
6
 
5
7
  spritekitnodeをタップしたらMFMailComposeViewControllerでメールの作成画面を表示し、送信/下書き/キャンセルのいずれかが処理されたらメールの作成画面を閉じたいです。
6
8