我的应用程序中有一个非常小的聊天。每当用户收到消息时,服务器都会发送通知。在 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)
此外,我可以正确获取数据。
问题是它不会重新加载表视图的数据!!
有没有人有任何解决方案,为什么会发生这种情况? …