0
func setUpLocalNotification(){
let calendar = NSCalendar(identifier: .gregorian)!
var dateFire = Date()
var fireComponents = calendar.components([NSCalendar.Unit.day,NSCalendar.Unit.month,NSCalendar.Unit.year,NSCalendar.Unit.hour,NSCalendar.Unit.minute], from: dateFire)
fireComponents.year = addAlarm.year
fireComponents.month = addAlarm.month
fireComponents.day = addAlarm.day
fireComponents.hour = addAlarm.hour
fireComponents.minute = addAlarm.minute
dateFire = calendar.date(from: fireComponents)!
let localNotification = UILocalNotification()
localNotification.fireDate = dateFire
localNotification.alertBody = addAlarm.msg
localNotification.soundName = UILocalNotificationDefaultSoundName
localNotification.userInfo = ["Uid" : addAlarm.id]
UIApplication.shared.scheduleLocalNotification(localNotification)
}
我想在含有msg的addAlarm中进行火灾通知。 我在main.swift中做了这个,不工作 我该怎么做才能做到这一点?在appdelegate添加这个? 我是swift初学者。请帮忙...swift如何在特定时间设置通知
请点击此链接: - https://stackoverflow.com/questions/37938771/uilocalnotification-is-deprecated-in-ios10 – Pushpendra
感谢评论它是有用的 –