我正在使用Pusher库创建聊天应用程序。连接正确,但当我聊天约10分钟连接失败并在pushe应用程序帐户的调试控制台腾空,导致没有实时消息。我已经实现了委托方法,但是当连接空出时,委托方法不会调用。
用于创建推送客户端:
client = [PTPusher pusherWithKey:@"XXXXXXXXXXXXXX" delegate:self encrypted:NO];
client.reconnectAutomatically = YES;
client.reconnectDelay = 30;
[client connect];
代表方法:
(void)pusher:(PTPusher *)client1 connectionDidDisconnect:(PTPusherConnection *)连接 { 可达性*可达性= [Reachability reachabilityForInternetConnection];
if([reachability currentReachabilityStatus] == NotReachable){ //此时尝试重新连接毫无意义 client1.reconnectAutomatically = NO;
// start observing the reachability status to see when we come back online
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(reachabilityChanged:)
name:kReachabilityChangedNotification
对象:可达性];
[reachability startNotifier];
} }
(void)reachabilityChanged:(NSNotification *)注意 { 可达性*可达性= note.object;
if([reachability currentReachabilityStatus]!= NotReachable){ //我们似乎有某种网络可达性,所以再试一次 // =<#获取推送器实例#> PTPusher * pusher = [PTPusher pusherWithKey:@“XXXXXXXXXXXXXXXX”委托:自加密:否];
[pusher connect];
// we can stop observing reachability changes now
// [[NSNotificationCenter defaultCenter] removeObserver:self]; // [reachability stopNotifier];
// re-enable auto-reconnect
pusher.reconnectAutomatically = YES;
} }