【问题标题】:Parse SDK SaveInBackground never goes in call backParse SDK SaveInBackground 永远不会进入回调
【发布时间】:2019-10-04 10:46:47
【问题描述】:

所以我的应用中有聊天室和聊天消息

如果有未读消息,我会发送 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() 之后没有其他行被执行?

标签: swift parse-platform


【解决方案1】:

我认为您不应该在后台线程上调用 saveEventually()。 saveEventually() 方法已经设计为使用后台线程。

试试这个...

if hasUnreadMessages || getMessagesNow {
            self.thisRoom.readBy!.append(self.currentUser.objectId!)
            self.thisRoom.saveEventually()
    }

您可以在此处的文档中查看此方法的工作原理:https://docs.parseplatform.org/ios/guide/#saving-objects-offline

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-18
    • 1970-01-01
    • 2012-02-18
    相关资源
    最近更新 更多