###前提・実現したいこと
タイマーを作っているのですが、アラーム音を鳴らすコードが書けなくて困っています。iPhoneにデフォで入ってるアラーム1種類、できれば数種類、欲を言えば、musicの音楽まで設定できればいいなと思ってます。
###発生している問題・エラーメッセージ
appdelegateの方は難しくてエラー処理してることくらいしか分かりませんでした。
scehdulerの方も変数?がかろうじてわかるくらいで何をしているかがわからないです
###該当のソースコード
scheduler.swiftの一部分
func setNotificationWithDate(_ date: Date, onWeekdaysForNotify weekdays:[Int], snoozeEnabled:Bool, onSnooze: Bool, soundName: String, index: Int) { let AlarmNotification: UILocalNotification = UILocalNotification() AlarmNotification.alertBody = "Wake Up!" AlarmNotification.alertAction = "Open App" AlarmNotification.category = "myAlarmCategory" //アラームの音楽を設定 AlarmNotification.soundName = soundName + ".mp3" //時間の設定 AlarmNotification.timeZone = TimeZone.current let repeating: Bool = !weekdays.isEmpty AlarmNotification.userInfo = ["snooze" : snoozeEnabled, "index": index, "soundName": soundName, "repeating" : repeating] //repeat weekly if repeat weekdays are selected //no repeat with snooze notification if !weekdays.isEmpty && !onSnooze{ AlarmNotification.repeatInterval = NSCalendar.Unit.weekOfYear } let datesForNotification = correctDate(date, onWeekdaysForNotify:weekdays) syncAlarmModel() for d in datesForNotification { if onSnooze { alarmModel.alarms[index].date = Scheduler.correctSecondComponent(date: alarmModel.alarms[index].date) } else { alarmModel.alarms[index].date = d } AlarmNotification.fireDate = d UIApplication.shared.scheduleLocalNotification(AlarmNotification) } setupNotificationSettings() }
###試したこと
https://github.com/natsu1211/Alarm-ios-swift
のプログラムのscheduler.swiftとappdelegate.swiftを読んで理解しようとしているのですが、難しくて困っているので助けて欲しいです。よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー