解析实时查询处理错误

时间:2018-02-21 21:32:53

标签: ios swift parse-platform server real-time

我正在使用解析实时查询进行实时通信,并且适用于所有类型的事件,但我的问题是服务器断开连接或互联网连接已关闭,那么我如何处理错误阻止? 我尝试将订阅中的错误阻止作为事件

.handleError(<#T##handler: (PFQuery<Blocks>, Error) -> Void##(PFQuery<Blocks>, Error) -> Void#>)

但没有成功,我想捕获记录的错误

2018-02-21 22:14:55.050543+0100 Youz[2095:1024917] TCP Conn 0x106d13f40 
Failed : error 0:50 [50]
2018-02-21 22:14:55.051443+0100 Youz[2095:1024955] ParseLiveQuery: 
WebSocket did disconnect with error: Optional(Error 
Domain=NSPOSIXErrorDomain Code=50 "Network is down" UserInfo=
{_kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1})
2018-02-21 22:14:55.057945+0100 Youz[2095:1024917] [] 
nw_connection_get_connected_socket 971 Connection has no connected 
handler

1 个答案:

答案 0 :(得分:0)

您可以使用NSNotificationCenter捕获Websocket事件。

就是这样

-(void)OnWebsocketConnected:(NSNotification *)noti {

DLogInfo(@"OnWebsocketConnected, noti= %@", noti);

}

-(void)OnWebsocketDisconnected:(NSNotification *)noti {

DLogInfo(@"OnWebsocketDisconnected, noti= %@", noti);

// can't recover lost data on Parse live query, we need to query manually.

}

-(void)OnWebsocketError:(NSNotification *)noti {

DLogInfo(@"OnWebsocketError, noti= %@", noti);

}

-(无效)初始化程序{

......

[[NSNotificationCenter defaultCenter] addObserver:自我选择器:@selector(OnWebsocketConnected :)名称:@“ WebsocketDidConnectNotification”对象:无];          [[NSNotificationCenter defaultCenter] addObserver:自我选择器:@selector(OnWebsocketDisconnected :)名称:@“ WebsocketDidDisconnectNotification”对象:无];          [[NSNotificationCenter defaultCenter] addObserver:自我选择器:@selector(OnWebsocketError :)名称:@“ WebsocketDisconnectionErrorKeyName”对象:无];

.......

}

相关问题