【发布时间】:2016-01-20 19:25:51
【问题描述】:
我有下一个代码:
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)
但它已被弃用。搜索了很多,但无法将其转换为 Swift2。谁能帮我解决这个问题:
notification.repeatInterval = NSCalendarUnit.CalendarUnitHour
【问题讨论】:
-
@LeoDabus 我做了,但它不起作用。它不发送通知 =/
-
检查一下,您注册了通知吗? stackoverflow.com/a/34575836/2303865
-
@LeoDabus 是的。在第一次启动时,它会询问我有关通知的信息。我已将以上所有行放入 showNotification() 函数并在 viewWillDisappear 上调用它。但它甚至根本不调用
标签: ios swift uilocalnotification nscalendar