【问题标题】:Parse Live Query handling Error解析实时查询处理错误
【发布时间】:2018-02-21 21:32:52
【问题描述】:

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

.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

【问题讨论】:

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


    【解决方案1】:

    您可以使用 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);
    

    }

    -(void) 初始化器 {

    ......

    [[NSNotificationCenter defaultCenter] addObserver:self 选择器:@selector(OnWebsocketConnected:) name:@"WebsocketDidConnectNotification" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self 选择器:@selector(OnWebsocketDisconnected:) name:@"WebsocketDidDisconnectNotification" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self 选择器:@selector(OnWebsocketError:) name:@"WebsocketDisconnectionErrorKeyName" object:nil];

    .......

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-27
      • 1970-01-01
      • 2016-02-07
      • 2011-03-11
      • 1970-01-01
      • 1970-01-01
      • 2012-03-03
      • 1970-01-01
      相关资源
      最近更新 更多