尝试创建本地通知但在 swift 2 中出现错误“无法调用非函数类型 uilocalnotification 的值”
trying to create a local notification but getting error " cannot call value of non function type uilocalnotification " in swift 2
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var dateComp:NSDateComponents = NSDateComponents()
dateComp.year = 2015;
dateComp.month = 11;
dateComp.day = 20;
dateComp.hour = 0;
dateComp.minute = 10;
dateComp.timeZone = NSTimeZone.systemTimeZone()
var calendar:NSCalendar = NSCalendar(calendarIdentifier: NSGregorianCalendar)!
var date:NSDate = calendar.dateFromComponents(dateComp)!
//var date:NSDate = calendar.dateFromComponents(dateComp)
var notification:UILocalNotification = UILocalNotification()
notification.category = "FIRST_CATEGORY"
notification.alertBody = "HI, noti "
notification.fireDate = date
UIApplication.sharedApplication().scheduledLocalNotifications(notification)
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
//trying to create a local notification but getting error " cannot call value of non function type uilocalnotification " in swift 2
您需要致电 scheduleLocalNotification
,而不是 scheduledLocalNotifications
(注意时间表不是时间表 d):
UIApplication.sharedApplication().scheduleLocalNotification(notification)
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var dateComp:NSDateComponents = NSDateComponents()
dateComp.year = 2015;
dateComp.month = 11;
dateComp.day = 20;
dateComp.hour = 0;
dateComp.minute = 10;
dateComp.timeZone = NSTimeZone.systemTimeZone()
var calendar:NSCalendar = NSCalendar(calendarIdentifier: NSGregorianCalendar)!
var date:NSDate = calendar.dateFromComponents(dateComp)!
//var date:NSDate = calendar.dateFromComponents(dateComp)
var notification:UILocalNotification = UILocalNotification()
notification.category = "FIRST_CATEGORY"
notification.alertBody = "HI, noti "
notification.fireDate = date
UIApplication.sharedApplication().scheduledLocalNotifications(notification)
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
//trying to create a local notification but getting error " cannot call value of non function type uilocalnotification " in swift 2
您需要致电 scheduleLocalNotification
,而不是 scheduledLocalNotifications
(注意时间表不是时间表 d):
UIApplication.sharedApplication().scheduleLocalNotification(notification)