1 Reply
      Latest reply: May 17, 2017 12:42 AM by jorisvm RSS
      amit_pune Level 1 Level 1 (0 points)

        I am getting Start date and End date from webservices,

        I want to send local notification between that Two dates at perticular time,

        Can anybody please help in this??

        • Re: Need to send local notification between two dates?
          jorisvm Level 2 Level 2 (40 points)

          Hi

           

          let currentDate = Date()
          //startDate
          var sDateComponents = DateComponents()
          sDateComponents.year = 2017
          sDateComponents.month = 05
          sDateComponents.day = 18
          sDateComponents.hour = 08
          sDateComponents.minute = 15
          sDateComponents.second = 0
          //endDate
          var eDateComponents = DateComponents()
          eDateComponents.year = 2017
          eDateComponents.month = 05
          eDateComponents.day = 20
          eDateComponents.hour = 08
          eDateComponents.minute = 15
          eDateComponents.second = 0
          //create Date
          let calendar = Calendar(identifier: .gregorian)
          let startDate = calendar.date(from: sDateComponents)!
          let endDate = calendar.date(from: eDateComponents)!
          //define Interval
          let midStartEndInterval = endDate.timeIntervalSince(startDate as Date) / 2
          let interval = startDate.timeIntervalSince(currentDate as Date) + midStartEndInterval
          //create the notification with your interval
          let notificationTrigger = UNTimeIntervalNotificationTrigger(timeInterval: interval, repeats: false)
          ...
          

           

          Have fun,

          Joris