-1

こんにちは、日付/時刻通知を実装しようとしていますが、日付が 2 時間ずれています。

日付選択時のコード

func SelectTime(sender: UIView){

    formatter.timeZone = TimeZone.autoupdatingCurrent
    let timePicker = ActionSheetDatePicker(title: "Time:", datePickerMode: UIDatePickerMode.time, selectedDate: userDate, doneBlock: {
        picker, userDateWithTime, index in

        self.formatter.timeZone = TimeZone.autoupdatingCurrent

        self.formatter.dateFormat = "yyyy MMMM dd, HH:mm"
        self.dateSelected.text = self.formatter.string(for: userDateWithTime)

        //print("User date picked \(self.formatter.string(from: userDateWithTime as! Date))")
        return

通知を作成するためのコード

let uuid = UUID().uuidString
    let notification = UNMutableNotificationContent()
    notification.title = "Plus - Todo"
    //notification.subtitle
    notification.body = taskText.text!

    let calendar = Calendar.current
    let dateComponents = calendar.dateComponents(in: .current, from: userDateWithTime)

    //let dateComponents = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute], from: correctDate!)


    let notificationTrigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: false)
    //let notificationTrigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
    let request = UNNotificationRequest(identifier: uuid, content: notification, trigger: notificationTrigger)

    UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
4

1 に答える 1