I am creating a chat application using Pusher library. connection is made correctly but when I chat for about near about 10 minutes connection fail and vacated in debug console of pushe app account and result in no real time messaging any more. I have implemented delegate method but delegate method does not call when connection vacated.
For creating pusher client:
client = [PTPusher pusherWithKey:@"XXXXXXXXXXXXXX" delegate:self encrypted:NO];
client.reconnectAutomatically = YES;
client.reconnectDelay = 30;
[client connect];
Delegate Methods:
(void)pusher:(PTPusher *)client1 connectionDidDisconnect:(PTPusherConnection *)connection { Reachability *reachability = [Reachability reachabilityForInternetConnection];
if ([reachability currentReachabilityStatus] == NotReachable) { // there is no point in trying to reconnect at this point client1.reconnectAutomatically = NO;
// start observing the reachability status to see when we come back online [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification
object:reachability];
[reachability startNotifier];
} }
(void)reachabilityChanged:(NSNotification *)note { Reachability *reachability = note.object;
if ([reachability currentReachabilityStatus] != NotReachable) { // we seem to have some kind of network reachability, so try again //= <# get the pusher instance #> PTPusher *pusher = [PTPusher pusherWithKey:@"XXXXXXXXXXXXXXXX" delegate:self encrypted:NO];
[pusher connect]; // we can stop observing reachability changes now
// [[NSNotificationCenter defaultCenter] removeObserver:self]; // [reachability stopNotifier];
// re-enable auto-reconnect pusher.reconnectAutomatically = YES;
} }