从 AppDelegate 发送本地通知时出现 NSInvalidArgumentException

NSInvalidArgumentException when sending local notification from AppDelegate

我想在应用程序处于后台时用户点击收到的通知时打开特定视图。我正在发布来自 appDelegate 的通知,如下所示:

    func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
    if let info = notification.userInfo {
        // Check if value present before using it
        if let s = info["CallIn"] {
            if(s as! String == "10minBeforeMeeting"){
                NSNotificationCenter.defaultCenter().postNotificationName("EventListShouldRefresh", object: self)
            }
            if(s as! String == "CallInNotification"){
                if let UUID = info["UUID"]{

                    print("ha: \(UUID)")
                    NSNotificationCenter.defaultCenter().postNotificationName("OpenDetailViewOfMeeting", object: self, userInfo: ["UUID":UUID])
                }
            }
        }
        else {
            print("no value for key\n")
        }
    }
    else {
        print("wrong userInfo type")
    }
}

在 class 中,我有这个通知的观察者:

//in viewDidLoad:
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "openDetailView", name: "OpenDetailViewOfMeeting", object: nil)




func openDetailView(notification: NSNotification) {
    let userInfo = notification.userInfo as! [String: AnyObject]
    let UUIDunbind = userInfo["UUID"] as! String

    let events = CalendarController.sharedInstance.todaysMeetings()
    for event in events {
        if(event.UUID == UUIDunbind){

            let detailViewController = DetailViewController()
            detailViewController.meeting = event

            self.mainViewController.showDetailViewController(detailViewController, sender: self)
        }
    }
}

当我收到通知时,我收到了 NSInvalidArgumentException: 似乎它甚至没有进入方法 openDetailView。在其他地方,我使用完全相同的结构并且它有效(尽管通知不是从 appDelegate 发布的,而是直接从某些 class 发布的)。 错误日志:

** * 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因:'-[CallIn.ViewController openDetailView]:无法识别的选择器发送到实例 0x7f9623c4d330'

我做错了什么?

您的选择器结构中缺少 :,它表示 openDetailView 方法中的参数 notification

NSNotificationCenter.defaultCenter().addObserver(self, selector: "openDetailView:", name: "OpenDetailViewOfMeeting", object: nil)

如果您需要更多信息,可以找到文档 here