trying to create a local notification but getting error “ cannot call value of non function type uilocalnotification ” in swift 2 [closed]

耗尽温柔 提交于 2019-12-11 12:24:38

问题


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 

回答1:


You need to call scheduleLocalNotification, not scheduledLocalNotifications (note schedule not scheduled):

UIApplication.sharedApplication().scheduleLocalNotification(notification)


来源:https://stackoverflow.com/questions/33812208/trying-to-create-a-local-notification-but-getting-error-cannot-call-value-of-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!