swift - 单击推送通知时应用程序崩溃

标签 swift apple-push-notifications crashlytics

我在字典中有一个 Web 服务响应,我按日期对其进行排序并将其显示在 TableView (X View Controller )中。单击推送通知时,我会将其重定向到上面提到的 (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()
}

在 View Controller 中:

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

最佳答案

删除或评论下面的方法将帮助您解决问题。

override func viewWillDisappear(_ animated: Bool) {
   NotificationCenter.default.removeObserver(self)
}

关于swift - 单击推送通知时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49426614/

相关文章:

android - 无法运行项目 - Android Studio 2.0 Crashlytics 问题

swift - Firebase 数据与 Eureka 和 Init

swift - 按下按钮时将 UIViewController .xib 添加到 UIViewController

iphone - 当用户禁用推送时,iOS 应用程序应该做什么?

ios - “证书 bundleId 与您应用的证书不匹配”Firebase 云消息传递

ios - iOS 推送通知的系统声音

crashlytics - 为 Beta 测试人员自动更新 iOS 应用程序?

firebase - 无崩溃统计监视器在 Flutter 中的 Firebase Crashlytics 中不起作用

ios - 在 UIAlertController SWIFT 中为每个图像添加一个动画图像

ios - Firebase 存储图像未在 Tableview 中下载