0

I have the next code:

var notification = UILocalNotification()
    notification.alertBody = "Message" // text that will be displayed in the notification
    notification.fireDate = NSDate()  // right now (when notification will be fired)
    notification.soundName = UILocalNotificationDefaultSoundName // play default sound

    let calendar = NSCalendar.currentCalendar()
    let components = calendar.components([.Minute], fromDate: NSDate())

    notification.repeatInterval = NSCalendarUnit.CalendarUnitHour // this line defines the interval at which the notification will be repeated
    UIApplication.sharedApplication().scheduleLocalNotification(notification)

but it's deprecated. Searched a lot, but couldn't convert it to Swift2. Can anyone help me with the line:

notification.repeatInterval = NSCalendarUnit.CalendarUnitHour
John Doe
  • 511
  • 1
  • 6
  • 13
  • @LeoDabus I did, but it doesn't work. It doesn't send notification =/ – John Doe Jan 20 '16 at 19:36
  • Checki this have you registered for notifications? http://stackoverflow.com/a/34575836/2303865 – Leo Dabus Jan 20 '16 at 19:41
  • @LeoDabus yes. On the first launch it asks me about notifications. I've putted all lines above into showNotification() func and call it on viewWillDisappear. But it even doesn't call at all – John Doe Jan 20 '16 at 19:46

1 Answers1

0

Enumerations in Swift 2 are much better then in Objective-C.

Try the next line:

notification.repeatInterval = NSCalendarUnit.Hour

It should be working.

Alexander Perechnev
  • 2,797
  • 3
  • 21
  • 35