2
Printing description of localNotification:

{fire date = Wednesday, August 5, 2015 at 9:00:00 AM India Standard Time, time zone = (null), repeat interval = NSCalendarUnitDay, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Thursday, August 6, 2015 at 9:00:00 AM India Standard Time, user info = (null)}

As you see the Time is 9:00:00 AM morning but it never fires here what i am doing

  • I am testing on Simulator by changing my Mac Time , is that the case ?
  • i have also tired to change the my mac time to next fire date , Still not working .
  • will these work perfectly in Live device ?

Update Code

 var calendar = NSCalendar.currentCalendar()
      //  calendar.timeZone = NSTimeZone(forSecondsFromGMT: 0)
        let comp = NSDateComponents()
        //comp.timeZone = NSTimeZone(forSecondsFromGMT: 0)
        comp.day = NSDate().day()
        comp.month = NSDate().month()
        comp.year = NSDate().year()


        comp.hour = date.hour()
        comp.minute = date.minute()
        var grouptimestamp = calendar.dateFromComponents(comp)?.getCurrentTimeStemp()

        var minutes = self.getMinutestFromTimestemp(NSDate.getCurrentTimeStemp() - grouptimestamp!)

        if minutes > 59 {
            println("Missed")
        }else if minutes < -5 {
            println("Early")
        }else{
            println("Takenow")
        }

        UIApplication.sharedApplication().cancelAllLocalNotifications()
        var localNotification:UILocalNotification = UILocalNotification()
        localNotification.alertAction = "Myplan"
        localNotification.alertBody = "Woww it works!!"
        localNotification.fireDate = NSDate(timeIntervalSince1970: NSTimeInterval(grouptimestamp!))
        localNotification.repeatInterval = NSCalendarUnit.CalendarUnitDay
        UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
hardikdevios
  • 1,779
  • 14
  • 33

1 Answers1

0

This is because the you have not set the timezone to the system timezone. By default, it sets the timezone according to your location and not according to the system time. Try adding this to your code:

    notification.timeZone = NSTimeZone.systemTimeZone()

This will change you notification timezone to the system timezone and then the notification will fire up if you change the time.

Hope this helps :)

bhakti123
  • 833
  • 10
  • 22