あなたはカレンダーオブジェクトを作成し、comps.weekday、comps.hourとcomps.minuteプロパティであなたの曜日と時刻の値を設定する必要があります。
あなたのメッセージについては、notification content.bodyプロパティで設定します。
import UserNotifications
let calendar = NSCalendar.init(calendarIdentifier: .gregorian)
calendar?.locale = NSLocale.current
let year = calendar?.component(.year, from: date)
let month = calendar?.component(.month, from: date)
let cal = Calendar.current
var comps = cal.dateComponents([.weekOfYear, .yearForWeekOfYear], from: date)
comps.weekday = i // Monday - Friday
comps.hour = j
comps.minute = minute
comps.year = year
comps.month = month
let notificationDate = cal.date(from: comps)!
let interval = String.init(format: "%d%d%d", i,j,minute)
if #available(iOS 10.0, *) {
let triggerDate = Calendar.current.dateComponents([.weekday,.hour,.minute], from: notificationDate as Date)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDate,
repeats: true)
let content = UNMutableNotificationContent()
content.title = DataManager.sharedInstance.notificationTitle
content.body = String.init(format: "%@", DataManager.sharedInstance.notificationMessage)
content.sound = UNNotificationSound.default()
let request = UNNotificationRequest(identifier: String(interval), content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) {(error) in
if let error = error {
print(error)
}
}
} else {
// ios 9
// Fallback on earlier versions
let notification = UILocalNotification()
/* Time and timezone settings */
notification.fireDate = date
notification.repeatInterval = NSCalendar.Unit.weekday
notification.timeZone = NSCalendar.current.timeZone
notification.alertBody = "message"
notification.userInfo = [ "title" : String(interval)]
/* Schedule the notification */
UIApplication.shared.scheduleLocalNotification(notification)
}
UPDATED ANSWER
- あなたのJSONはNSDictionaryのオブジェクトのNSArrayのに変換します。 NSJSonSerialisationクラスを使用します。
- forループをNSArrayインスタンスで実行し、NSDictionaryオブジェクトに1つずつアクセスします。
- NSDictionaryのvalueForKeyメソッドを使用します。キー名を渡し、辞書から値を取得します。
私はこれを試してみませんか?キー "time"と "hour"にアクセスし、comps.hourとcomps.weekdayにそれを当てる方法を知らない:( – user8172235
@ user8172235 updated jsonからのデータにアクセスするためのステップの私の答え。歓声:) – Basheer