I want to specify a notification time in Swift LocalNotification

Asked 2 years ago, Updated 2 years ago, 74 views

US>Error Contents
cannot assign a value of type "NSDateFormatter" to a value of type "NSDate"
US>Error points
notification.fireDate=myDateFormatter

let myDateFormatter=NSDateFormatter()
myDateFormatter.locale=NSLocale(localeIdentifier: "ja_JP")
myDateFormatter.dateFormat="yyyy/MM/dd hh:mm"

let mySelectedDate: NSSstring=myDateFormatter.stringFromDate(sender.date)
dateField.text = mySelectedDate as String


UIAApplication.sharedApplication().cancelAllLocalNotifications();
let setting = UIUserNotificationSettings (forTypes: [.Sound, .Alert], categories:nil)
UIAApplication.sharedApplication().registerUserNotificationSettings(setting)
let notification = UILocalNotification()
notification.fireDate=myDateFormatter
notification.timeZone=NSTimeZone.defaultTimeZone()
notification.alertBody="Notification"
notification.alertAction="OK"
notification.soundName = UILocalNotificationDefaultSoundName
UIAApplication.sharedApplication().scheduleLocalNotification(notification);

ios swift iphone

2022-09-30 11:28

1 Answers

As you can see in the error message, myDateFormatter is an instance of NSDateFormatter, so it is not NSDate.

Would you like to substitute fireDate for sender.date?


2022-09-30 11:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.