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

时间:2016-01-13 12:36:35

标签: ios swift uilocalnotification

当应用在后台时,我想在用户点按收到的通知时打开特定视图。我正在发布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")
    }
}

在课堂上,我是这个通知的观察者:

//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发布,而是直接从某个类发布)。 错误日志:

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

我做错了什么?

1 个答案:

答案 0 :(得分:0)

您在选择器结构中缺少ForeignKey,它代表:方法中的参数notification

openDetailView

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