所以我的应用程序中有聊天室和聊天消息
如果有未读消息,我会发送 ChatRoomVC 并更新消息已读的聊天室。这是我的代码
if hasUnreadMessages || getMessagesNow {
DispatchQueue.background(delay: 0, background: {
self.thisRoom.readBy!.append(self.currentUser.objectId!)
self.thisRoom.saveEventually { (saved, err) in
if err == nil {
NSLog("AppDebug -Message Unread updated")
DispatchQueue.main.async {
NotificationCenter.default.post(name: Notification.Name(rawValue: "updateBadgeValue"), object: nil)
}
} else {
print(err!.localizedDescription)
}
}
}, completion: nil)
}
所以它永远不会保存在服务器上,也不会成功或错误回调
我尝试了 saveInBackground..但这只是挂起了应用程序
如果我删除后台调度。它也会挂起应用程序
知道为什么会发生这种情况吗? TIA
编辑:一旦调用 saveEventually 或 SaveInBackground,CPU 使用率就会上升 60-80%,并且永远不会下降。因此,如果我返回并打开另一个有未读消息的房间..它会达到 150-160%...所以..on
最佳答案
我认为您不应该在后台线程上调用 saveEventually() 。 saveEventually() 方法已设计为使用后台线程。
试试这个...
if hasUnreadMessages || getMessagesNow {
self.thisRoom.readBy!.append(self.currentUser.objectId!)
self.thisRoom.saveEventually()
}
您可以在此处的文档中了解此方法的工作原理:https://docs.parseplatform.org/ios/guide/#saving-objects-offline
关于swift - Parse SDK SaveInBackground 永远不会回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58234887/