小编jac*_*ack的帖子

收到通知时刷新表视图

我的应用程序中有一个非常小的聊天。每当用户收到消息时,服务器都会发送通知。在 appDelegate 中,我实现了以下代码:

@available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        completionHandler(.alert)
//        print(UNNotificationAction)
        print(" recieved")
        if notification.request.content.title.contains("Message")
        {
            print("sub")
            print(notification.request.content.subtitle)
            print("body")
            print(notification.request.content.body)
            print("it containt DM ?")

            let storyboard:UIStoryboard = UIStoryboard(name:"Chat", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "chatRoomVc") as! ChatRoomViewController
            vc.becomeFirstResponder()

            vc.setRefreshListener {
                print("triggered")
            }

        }

    }
Run Code Online (Sandbox Code Playgroud)

每当它运行时,它都会调用 API 并获取聊天数据。下面的代码显示了它如何获取数据:

 func setRefreshListener(listener:@escaping ()->Void){
    refreshListener = listener
    presenter.getttingChatRoomData(aptId: UserDefaults.standard.string(forKey: userAPTID)!, id: UserDefaults.standard.string(forKey: userID)!)
    presenter.attachView(view: self)
    super.loadView()
    super.reloadInputViews()
    tableView.reloadData()


}
Run Code Online (Sandbox Code Playgroud)

此外,我可以正确获取数据。

问题是它不会重新加载表视图的数据!!

有没有人有任何解决方案,为什么会发生这种情况? …

listener uitableview push-notification ios swift

2
推荐指数
1
解决办法
2516
查看次数

标签 统计

ios ×1

listener ×1

push-notification ×1

swift ×1

uitableview ×1