How to create a todo with notification in swift

Asked 2 years ago, Updated 2 years ago, 37 views

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.

swift

2022-09-30 19:25

1 Answers

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))


2022-09-30 19:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.