I am using xmppframework to develop an iOS chat application. The issue is, I expect the XMPP connection to go offline when the app is minimised/not active in some time.
But to my surprise, the user is not going offline. I believe thats my issue. The reason, I want the user to go offline is that when the user is offline, and the user receives a push notification (through APNS), I have programmed in such a way that the XMPP connection is reestablished when the user clicks on the push notification and launches the app.
This works fine when the user goes offline
But when the user is online ( say 12 hrs the user is online) for a long time after the app is minimised (which is happening to me at the moment), when I try to send a message to the user, the user is not receiving the internal push notification nor the messages which I am sending though the user status is ONLINE .This mostly happens in iPhone 4 running in version iOS7.
Below is the applicationDidEnterBackground code
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSMutableArray *tempaaray=[DatabaseAccess getBedageValueFromConversation];
NSLog(@"getBedageValueFromConversation is :%lu",(unsigned long)tempaaray.count);
//================XMPP
// Use this method to release shared resources, save user data, invalidate timers, and store
// enough application state information to restore your application to its current state in case
// it is terminated later.
//
// If your application supports background execution,
// called instead of applicationWillTerminate: when the user quits.
DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);
#if TARGET_IPHONE_SIMULATOR
DDLogError(@"The iPhone simulator does not process background network traffic. "
@"Inbound traffic is queued until the keepAliveTimeout:handler: fires.");
#endif
if ([application respondsToSelector:@selector(setKeepAliveTimeout:handler:)])
{
[application setKeepAliveTimeout:600 handler:^{
DDLogVerbose(@"KeepAliveHandler");
// Do other keep alive stuff here.
}];
}
}
Can I add the below line in the applicationDidEnterBackground delegate method
if (![xmppStream isDisconnected]) {
[self disconnect];
}
This will forcefully disconnect the user and make the user go offline every time the user minimises the app. And once he comes online, messages will resume. Or do I need to localise this code for only iPhone4 and iOS7 users?
Or is there any other good way of tackling this issue?
Please let me know