簡體   English   中英

從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")
    }
}

在課堂上,我是該通知的觀察者:

//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”

我究竟做錯了什么?

您的選擇器結構缺少一個: ,它表示openDetailView方法的參數notification

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

如果您需要更多信息,可以在此處找到文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM