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
感謝評論它是有用的 –