gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 13:47:13 25 4
gpt4 key购买 nike

当应用程序在后台时用户点击收到的通知时,我想打开特定 View 。我正在发布来自 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)

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

关于ios - 从 AppDelegate 发送本地通知时出现 NSInvalidArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34766936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com