質問編集履歴

1

コードで囲みました。

2018/05/24 05:30

投稿

-yoshi-
-yoshi-

スコア14

test CHANGED
File without changes
test CHANGED
@@ -1,5 +1,9 @@
1
1
  ### できていること
2
2
 
3
+
4
+
5
+ ```Swift
6
+
3
7
  import UIKit
4
8
 
5
9
  import UserNotifications
@@ -74,17 +78,19 @@
74
78
 
75
79
 
76
80
 
81
+ ```
82
+
83
+
84
+
77
85
  ↑↑このプログラムではボタンを押すと5秒後に通知が来ます。
78
86
 
79
87
 
80
88
 
81
89
  ### やろうとしていること
82
90
 
91
+
92
+
83
- import UIKit
93
+ ```Swift
84
-
85
- import UserNotifications
86
-
87
-
88
94
 
89
95
  class ViewController: UIViewController {
90
96
 
@@ -94,7 +100,7 @@
94
100
 
95
101
 
96
102
 
97
- let ss : [Int] = [10]
103
+ let ss : [Double] = [10.0]
98
104
 
99
105
 
100
106
 
@@ -158,15 +164,105 @@
158
164
 
159
165
 
160
166
 
167
+ ```
168
+
169
+
170
+
161
171
  ↑↑5秒後のところを定数にするとエラーが起きます。
162
172
 
163
173
  変数や定数で秒数を指定することはできないんでしょうか?
164
174
 
175
+ これでもエラーが出ました。
176
+
177
+ ですが、下のコードは定数を配列にしなかったらエラーが消えました。
178
+
179
+ ユーザーデフォルトを使っていて配列の最後のInt型をtimeIntervalに入れたいのですが、できますか?
180
+
181
+ よろしくお願いします。
182
+
183
+
184
+
185
+ ```Swift
186
+
187
+ class ViewController: UIViewController {
188
+
189
+
190
+
191
+ @IBAction func action(_ sender: Any) {
192
+
193
+
194
+
195
+ let ss = 10.0
196
+
197
+
198
+
199
+ let content = UNMutableNotificationContent()
200
+
201
+ content.title = "通知"
202
+
203
+ content.subtitle = "テスト"
204
+
205
+ content.body = "これはボディーです。"
206
+
207
+ content.badge = 1
208
+
209
+ content.sound = .default()
210
+
211
+
212
+
213
+ let trigger = UNTimeIntervalNotificationTrigger(timeInterval: ss, repeats: false)
214
+
215
+ let request = UNNotificationRequest(identifier: "あ", content: content, trigger: trigger)
216
+
217
+
218
+
219
+ UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
220
+
221
+
222
+
223
+ }
224
+
225
+
226
+
227
+
228
+
229
+ override func viewDidLoad() {
230
+
231
+ super.viewDidLoad()
232
+
233
+ // Do any additional setup after loading the view, typically from a nib.
234
+
235
+
236
+
237
+ UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge], completionHandler: {didAllow, error in})
238
+
239
+ }
240
+
241
+
242
+
243
+ override func didReceiveMemoryWarning() {
244
+
245
+ super.didReceiveMemoryWarning()
246
+
247
+ // Dispose of any resources that can be recreated.
248
+
249
+ }
250
+
251
+
252
+
253
+
254
+
255
+ }
256
+
257
+ ```
258
+
259
+
260
+
165
261
  初心者でわからないのでよろしくお願いします。
166
262
 
167
263
  ### エラー
168
264
 
169
- Cannot convert value of type '[Int]' to expected argument type 'TimeInterval' (aka 'Double')
265
+ Cannot convert value of type '[Double]' to expected argument type 'TimeInterval' (aka 'Double')
170
266
 
171
267
 
172
268