I'm trying to Implement chat module in my app. I am successfully done with Login
and Register
process from Simple Chat Demo into my app. It also returns user array of offline and online users.
Now after successfully log in I am getting below log :-
error:
2012-12-07 14:50:07.056 App[5324:790b] QBChatService/xmppStreamDidConnect
2012-12-07 14:50:08.285 App[5324:790f] QBChatService/xmppStreamDidAuthenticate
2012-12-07 14:51:08.291 App[5324:711f] QBChatService/xmppStreamDidDisconnect, error=Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo=0xb982330 {NSLocalizedDescription=Socket closed by remote peer}
And I'm not able to receive chat messages into my app.
Any suggestions ?
Edit :-
In my app, when login is done I am sending the login request to QuickBlox API
if(loginDone)
{
NSString *userName = [_textUsername.text stringByReplacingOccurrencesOfString:@"@" withString:@"_"];
NSString *userPass = [_textPassword.text stringByReplacingOccurrencesOfString:@"@" withString:@"_"];
// Authenticate user
[QBUsers logInWithUserLogin:userName password:userPass delegate:self context:userPass];
}
#pragma mark -
#pragma mark QBActionStatusDelegate
// QuickBlox API queries delegate
-(void)completedWithResult:(Result *)result context:(void *)contextInfo
{
// QuickBlox User authentication result
if([result isKindOfClass:[QBUUserLogInResult class]])
{
// Success result
if(result.success)
{
QBUUserLogInResult *res = (QBUUserLogInResult *)result;
// save current user
[[DataManager shared] setCurrentUser: res.user];
NSLog(@"%@",res.user);
[[[DataManager shared] currentUser] setPassword:(NSString *)contextInfo];
NSLog(@"%@",res.user);
// Login to Chat
[QBChat instance].delegate = self;
[[QBChat instance] loginWithUser:[[DataManager shared] currentUser]];
// Register as subscriber for Push Notifications
[QBMessages TRegisterSubscriptionWithDelegate:nil];
// send request for getting user's filelist
PagedRequest *pagedRequest = [[PagedRequest alloc] init];
[pagedRequest setPerPage:10];
[QBContent blobsWithPagedRequest:pagedRequest delegate:self];
[pagedRequest release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Errors"
message:[result.errors description]
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles: nil];
alert.tag = 1;
//[alert show];
[alert release];
[HUD hide:YES];
[self AfterLoginController];
}
}
}
-(void)completedWithResult:(Result *)result
{
if([result isKindOfClass:[QBUUserLogInResult class]]) // QuickBlox User authentication result
{
// Success result
if(result.success)
{
// If we are authenticating through Twitter/Facebook - we use token as user's password for Chat module
[self completedWithResult:result context:[BaseService sharedService].token];
}
}
else if ([result isKindOfClass:[QBCBlobPagedResult class]])
{
// Success result
if(result.success){
QBCBlobPagedResult *res = (QBCBlobPagedResult *)result;
// Save user's filelist
[DataManager shared].fileList = [[res.blobs mutableCopy] autorelease];
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[app startsendPresenceTimer];
[HUD hide:YES];
[self AfterLoginController];
}
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Errors"
message:[result.errors description]
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles: nil];
alert.tag = 1;
//[alert show];
[alert release];
[HUD hide:YES];
[self AfterLoginController];
}
}
Now in AppDelegate :-
- (void) startsendPresenceTimer
{
[QBChat instance].delegate = self;
// send presence
if(self.sendPresenceTimer == nil)
{
self.sendPresenceTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(sendPresence) userInfo:nil
repeats:YES];
}
if (self.requesAllUsersTimer == nil)
{
self.requesAllUsersTimer= [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(updateUsers) userInfo:nil repeats:YES];
}
[self.requesAllUsersTimer fire];
}
// send presence
- (void)sendPresence{
// presence in QuickBlox Chat
[[QBChat instance] sendPresence];
// presence in QuickBlox
[QBUsers userWithExternalID:1 delegate:nil];
}
- (void)updateUsers
{
// Retrieve all users
PagedRequest* request = [[PagedRequest alloc] init];
request.perPage = 100; // 100 users
[QBUsers usersWithPagedRequest:request delegate:self];
[request release];
}