IOS Parse LiveQuery:错误处理消息:可选(POSIXErrorCode:软件导致连接中止)
Posted
技术标签:
【中文标题】IOS Parse LiveQuery:错误处理消息:可选(POSIXErrorCode:软件导致连接中止)【英文标题】:IOS Parse LiveQuery: Error processing message: Optional(POSIXErrorCode: Software caused connection abort) 【发布时间】:2021-06-01 07:21:32 【问题描述】:我在 SwiftUI 中开发了一个应用程序,我还使用 Parse LiveQuery 聊天。 聊天实时完美运行,直到应用程序进入后台或手机屏幕关闭。 如果我收到新消息的通知并从通知中打开应用程序,则 LiveQuery 停止工作并收到错误消息:“Parse LiveQuery:错误处理消息:可选(POSIXErrorCode:软件导致连接中止)”
我注册了 Message 类
class Message: PFObject, PFSubclassing
@NSManaged var message : String
@NSManaged var receiver : PFObject
@NSManaged var thread_id : PFObject
@NSManaged var produs : PFObject
@NSManaged var sender : PFObject
@NSManaged var picture : PFObject
class func parseClassName() -> String
return "Message"
在 ChatView 上,我有 .onReceive,我在其中启动聊天和 liveQuery 功能
var messagesQuery: PFQuery<Message>
return (Message.query()?
.whereKey("thread_id", equalTo: self.mainThread_obj)
.order(byDescending: "createdAt")) as! PFQuery<Message>
self.StartMessagesLiveQuery(messagesQuery: messagesQuery)
函数 StartMessagesLiveQuery 是:
let subscription: Subscription<Message> = Client.shared.subscribe(messagesQuery)
subscription.handle(Event.created) query, object in
print("Live Query Trigered")
print(object)
DispatchQueue.global(qos: .background).async
///reading object and appending to array
唯一的问题是从通知打开应用程序时。
我有什么方法可以强制 ParseLiveQuery 重新连接?
错误堆栈:
2021-03-03 10:15:47.442021+0200 App[35496:6350370] [connection] nw_read_request_report [C2] Receive failed with error "Software caused connection abort"
2021-03-03 10:15:47.449044+0200 App[35496:6350370] [connection] nw_read_request_report [C3] Receive failed with error "Software caused connection abort"
2021-03-03 10:15:47.449291+0200 App[35496:6350370] [connection] nw_read_request_report [C1] Receive failed with error "Software caused connection abort"
2021-03-03 10:15:47.455008+0200 App[35496:6350370] [connection] nw_flow_add_write_request [C2.1 52.1.38.170:443 failed channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, dns)] cannot accept write requests
2021-03-03 10:15:47.455055+0200 App[35496:6350370] [connection] nw_write_request_report [C2] Send failed with error "Socket is not connected"
2021-03-03 10:15:47.455815+0200 App[35496:6350657] ParseLiveQuery: Error processing message: Optional(POSIXErrorCode: Software caused connection abort)
2021-03-03 10:15:47.456612+0200 App[35496:6350370] Task <F6A87098-D5D3-444B-B656-D1999D5089D1>.<44> HTTP load failed, 42/0 bytes (error code: -1005 [1:53])
2021-03-03 10:15:47.462120+0200 App[35496:6350657] Task <F6A87098-D5D3-444B-B656-D1999D5089D1>.<44> finished with error [-1005] Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo=_kCFStreamErrorCodeKey=53, NSUnderlyingError=0x282d11830 Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo=NSErrorPeerAddressKey=<CFData 0x280174aa0 [0x20a814660]>length = 16, capacity = 16, bytes = 0x100201bb344692570000000000000000, _kCFStreamErrorCodeKey=53, _kCFStreamErrorDomainKey=1, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <F6A87098-D5D3-444B-B656-D1999D5089D1>.<44>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <F6A87098-D5D3-444B-B656-D1999D5089D1>.<44>"
), NSLocalizedDescription=The network connection was lost., NSErrorFailingURLStringKey=https://site.b4a.app/classes/_User, NSErrorFailingURLKey=https://site.b4a.app/classes/_User, _kCFStreamErrorDomainKey=1
2021-03-03 10:15:47.462237+0200 App[35496:6350657] [Error]: The network connection was lost. (Code: 100, Version: 1.19.1)
2021-03-03 10:15:47.462335+0200 Bazar[35496:6350657] [Error]: Network connection failed. Making attempt 1 after sleeping for 1.588128 seconds.
在此之后网络连接恢复并且应用程序正常运行,只有 LiveQuery 不工作。
【问题讨论】:
你知道是哪一行报错了吗?你能分享完整的错误堆栈吗? 我不知道是哪一行导致了错误。我将在问题中提出的竞争错误堆栈 【参考方案1】:我想我已经解决了。 我修改了 StartMessagesLiveQuery 函数:
func StartMessagesLiveQuery(messagesQuery: PFQuery<Message>)
在我拥有的函数内部:
let subscription: Subscription<Message> = Client.shared.subscribe(messagesQuery)
subscription!.handle(Event.created) query, object in ...
现在我已经修改并放入了类
var subscription: Subscription<Message>?
var subscriber: ParseLiveQuery.Client!
在我修改过的函数中:
subscriber = ParseLiveQuery.Client()
subscription = subscriber.subscribe(messagesQuery)
【讨论】:
以上是关于IOS Parse LiveQuery:错误处理消息:可选(POSIXErrorCode:软件导致连接中止)的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 AFNetworking 2.0 处理 Parse.com Rest API 错误
如何处理 Parse.com 将 HTTP 错误转换为 NSError?
Dexie useLiveQuery hook 导致错误“TypeError: dexie.liveQuery is not a function”