Skip to main content
1 / 2
mmmm
  • 103
  • 7

Swift LocalNotificationで通知時間を指定したい

エラー内容
cannot assign a value of type "NSDateFormatter" to a value of type "NSDate"
エラー箇所
notification.fireDate = myDateFormatter

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

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


UIApplication.sharedApplication().cancelAllLocalNotifications();
let setting = UIUserNotificationSettings(forTypes: [.Sound, .Alert], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(setting)
let notification = UILocalNotification()

notification.fireDate = myDateFormatter
notification.timeZone = NSTimeZone.defaultTimeZone()
notification.alertBody = "通知だよ"
notification.alertAction = "OK"
notification.soundName = UILocalNotificationDefaultSoundName
UIApplication.sharedApplication().scheduleLocalNotification(notification);

}

mmmm
  • 103
  • 7