質問編集履歴
2
重複していた箇所の修正と,sendMail2にプログラムにメールアドレスを入力する方法で正しく動いているコードも追加しました.
test
CHANGED
File without changes
|
test
CHANGED
@@ -78,22 +78,6 @@
|
|
78
78
|
|
79
79
|
|
80
80
|
|
81
|
-
override func viewDidLoad() {
|
82
|
-
|
83
|
-
super.viewDidLoad()
|
84
|
-
|
85
|
-
setupLocationManager()
|
86
|
-
|
87
|
-
// デフォルト値
|
88
|
-
|
89
|
-
userDefaults.register(defaults: ["DataStore": "default"])
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
address.text = readData()
|
94
|
-
|
95
|
-
}
|
96
|
-
|
97
81
|
|
98
82
|
|
99
83
|
@IBAction func sendMail(sender: Any) {
|
@@ -122,6 +106,36 @@
|
|
122
106
|
|
123
107
|
}
|
124
108
|
|
109
|
+
|
110
|
+
|
111
|
+
@IBAction func sendMail2(sender: Any) {
|
112
|
+
|
113
|
+
let toRecipients2 = "xxx@co.jp"
|
114
|
+
|
115
|
+
if MFMailComposeViewController.canSendMail() {
|
116
|
+
|
117
|
+
let mail = MFMailComposeViewController()
|
118
|
+
|
119
|
+
mail.mailComposeDelegate = self
|
120
|
+
|
121
|
+
mail.setToRecipients([toRecipients2]) // 宛先アドレス
|
122
|
+
|
123
|
+
mail.setSubject("はじめまして"") // 件名
|
124
|
+
|
125
|
+
mail.setMessageBody("こんにちは", isHTML: false) // 本文
|
126
|
+
|
127
|
+
present(mail, animated: true, completion: nil)
|
128
|
+
|
129
|
+
} else {
|
130
|
+
|
131
|
+
print("送信できません")
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
125
139
|
func readData() -> String {
|
126
140
|
|
127
141
|
// Keyを指定して読み込み
|
1
address.textの説明のため,class ViewControllerを追加しました.
test
CHANGED
File without changes
|
test
CHANGED
@@ -39,6 +39,42 @@
|
|
39
39
|
|
40
40
|
|
41
41
|
```Swift
|
42
|
+
|
43
|
+
class ViewController: UIViewController, MFMailComposeViewControllerDelegate ,CLLocationManagerDelegate{
|
44
|
+
|
45
|
+
@IBOutlet weak var sendMail: UILabel!
|
46
|
+
|
47
|
+
@IBOutlet weak var address: UILabel!
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
var testText:String = "default"
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
//②UserDefaults のインスタンス
|
56
|
+
|
57
|
+
let userDefaults = UserDefaults.standard
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
var locationManager: CLLocationManager!
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
override func viewDidLoad() {
|
66
|
+
|
67
|
+
super.viewDidLoad()
|
68
|
+
|
69
|
+
setupLocationManager()
|
70
|
+
|
71
|
+
// デフォルト値
|
72
|
+
|
73
|
+
userDefaults.register(defaults: ["DataStore": "default"])
|
74
|
+
|
75
|
+
address.text = readData()
|
76
|
+
|
77
|
+
}
|
42
78
|
|
43
79
|
|
44
80
|
|