我在字典中有一个webservice响应,我按日期对其进行排序,并将其显示在tableview(X viewcontroller)中。单击推送通知时,我将其重定向到上面提到的(X)viewcontroller。但是当我点击通知时,应用程序崩溃了。有人可以帮我解决下面的崩溃日志吗?
Exception name: EXC_BAD_ACCESS / KERN_PROTECTION_FAILURE
1 CoreFoundation_CFStringCheckAndGetCharacters + 80812
2 CoreFoundation-[__NSCFString getCharacters:range:] + 80720
3 CoreFoundation isEqualToString + 1255332
4 CoreFoundation-[__NSSingleEntryDictionaryI objectForKey:] + 889612
5 Appname 4304500692 + 1521620
6 Appname 4304499340 + 1520268
7 Appname 4304580448 + 1601376
78 UIKit -[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion:] + 2640488
79 UIKit __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 13195140
80 UIKit-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 13194848
81 UIKit__125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 10498760
82 UIKit_performActionsWithDelayForTransitionContext + 12174280
83 UIKit -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 10498424
84 UIKit-[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 8288092
85 UIKit-[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 6853284
86 FrontBoardServices __80-[FBSSceneImpl updater:didUpdateSettings:withDiff:transitionContext:completion:]_block_invoke.362 + 52384
87 libdispatch.dylib _dispatch_client_callout + 6672
88 libdispatch.dylib _dispatch_block_invoke_direct$VARIANT$mp + 37372
89 FrontBoardServices __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 264180
90 FrontBoardServices -[FBSSerialQueue _performNext] + 263320
91 FrontBoardServices -[FBSSerialQueue _performNextFromRunLoopSource] + 264756
92CoreFoundation__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 964472
93 CoreFoundation __CFRunLoopDoSource0 + 964344
94 CoreFoundation __CFRunLoopDoSources0 + 962432
95 CoreFoundation __CFRunLoopRun + 953176
96 CoreFoundation CFRunLoopRunSpecific + 35924
97 GraphicsServices GSEventRunModal + 44928
98 UIKit UIApplicationMain + 472512
99 Appname 4303008020 + 28948
100 libdyld.dylib start + 5480
在Appdelegate中:
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ALERTHANDLER"), object: nil)
completionHandler()
}
在viewcontroller中:
override func viewWillAppear(_ animated: Bool) {
// response action
NotificationCenter.default.addObserver(self, selector: #selector(self.methodOfReceivedNotification), name: NSNotification.Name(rawValue: "ALERTHANDLER"), object: nil)
}
@objc func methodOfReceivedNotification(notification: NSNotification) {
let storyBoard: UIStoryboard = UIStoryboard(name: "MenuStoryboard", bundle: nil)
let newViewController1 = storyBoard.instantiateViewController(withIdentifier: "ViewController")
self.navigationController?.pushViewController(newViewController1, animated: true)
}
override func viewWillDisappear(_ animated: Bool) {
NotificationCenter.default.removeObserver(self)
}
答案 0 :(得分:1)
删除或评论以下方法将帮助您解决问题。
override func viewWillDisappear(_ animated: Bool) {
NotificationCenter.default.removeObserver(self)
}