I'm a beginner at Swift.I am currently working on the todo app, but I want to add a function such as notification when the date of the event I set is set, but I can't think of any method.
I was able to implement it until I saved the configuration items in coredata, but I would like you to tell me how to add the notification function.
I think it's better to use UILocalNotification
.Below is a sample.
// afterSec seconds of notification
func scheduleNotification(alert:String, afterSec:NSTimeInterval) {
leto=UILocalNotification()
o.fireDate=NSDate().dateByAddingTimeInterval(afterSec)
o.timeZone=NSTimeZone.defaultTimeZone()
o.alertBody=alert
UIAApplication.sharedApplication().scheduledLocalNotifications=[o]
}
Also, you must have the user choose to turn on the notification settings when the application starts.
UIAApplication.sharedApplication()
.registerUserNotificationSettings(
UIUserNotificationSettings (forTypes:UIUserNotificationType.Alert, categories:nil))
© 2024 OneMinuteCode. All rights reserved.