質問編集履歴
1
プログラムと自分なりのコメントを付け足しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -5,6 +5,10 @@
|
|
5
5
|
|
6
6
|
|
7
7
|
###発生している問題・エラーメッセージ
|
8
|
+
|
9
|
+
appdelegateの方は難しくてエラー処理してることくらいしか分かりませんでした。
|
10
|
+
|
11
|
+
scehdulerの方も変数?がかろうじてわかるくらいで何をしているかがわからないです
|
8
12
|
|
9
13
|
```
|
10
14
|
|
@@ -16,9 +20,75 @@
|
|
16
20
|
|
17
21
|
###該当のソースコード
|
18
22
|
|
23
|
+
scheduler.swiftの一部分
|
24
|
+
|
19
25
|
```
|
20
26
|
|
27
|
+
func setNotificationWithDate(_ date: Date, onWeekdaysForNotify weekdays:[Int], snoozeEnabled:Bool, onSnooze: Bool, soundName: String, index: Int) {
|
21
28
|
|
29
|
+
let AlarmNotification: UILocalNotification = UILocalNotification()
|
30
|
+
|
31
|
+
AlarmNotification.alertBody = "Wake Up!"
|
32
|
+
|
33
|
+
AlarmNotification.alertAction = "Open App"
|
34
|
+
|
35
|
+
AlarmNotification.category = "myAlarmCategory"
|
36
|
+
|
37
|
+
//アラームの音楽を設定
|
38
|
+
|
39
|
+
AlarmNotification.soundName = soundName + ".mp3"
|
40
|
+
|
41
|
+
//時間の設定
|
42
|
+
|
43
|
+
AlarmNotification.timeZone = TimeZone.current
|
44
|
+
|
45
|
+
let repeating: Bool = !weekdays.isEmpty
|
46
|
+
|
47
|
+
AlarmNotification.userInfo = ["snooze" : snoozeEnabled, "index": index, "soundName": soundName, "repeating" : repeating]
|
48
|
+
|
49
|
+
//repeat weekly if repeat weekdays are selected
|
50
|
+
|
51
|
+
//no repeat with snooze notification
|
52
|
+
|
53
|
+
if !weekdays.isEmpty && !onSnooze{
|
54
|
+
|
55
|
+
AlarmNotification.repeatInterval = NSCalendar.Unit.weekOfYear
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
let datesForNotification = correctDate(date, onWeekdaysForNotify:weekdays)
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
syncAlarmModel()
|
66
|
+
|
67
|
+
for d in datesForNotification {
|
68
|
+
|
69
|
+
if onSnooze {
|
70
|
+
|
71
|
+
alarmModel.alarms[index].date = Scheduler.correctSecondComponent(date: alarmModel.alarms[index].date)
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
else {
|
76
|
+
|
77
|
+
alarmModel.alarms[index].date = d
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
AlarmNotification.fireDate = d
|
82
|
+
|
83
|
+
UIApplication.shared.scheduleLocalNotification(AlarmNotification)
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
setupNotificationSettings()
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
}
|
22
92
|
|
23
93
|
```
|
24
94
|
|