I have create an application for chatting. I have use QuickBlox to chat with each other.
I have register two user and chat with each other it will work perfect. But when user logout and login again it will crash.
ERROR - Dialog have to be in memory cache!
EX: A and B user login with their device and chat with each other after that when they logout and login again and when they send message application crash.
LOGIN
- (void)loginWithQuickBlox:(NSString *)idandPassword {
[QBRequest logInWithUserLogin:idandPassword password:idandPassword successBlock:^(QBResponse *response, QBUUser *user)
{
// NSLog(@"User Id : %ld",(unsigned long)user.ID);
NSString *usrID=[NSString stringWithFormat:@"%ld",(unsigned long)user.ID];
[[NSUserDefaults standardUserDefaults]setObject:usrID forKey:@"LoginQuickbloxID"];
[self loginWithQuickBloxChat:idandPassword];
} errorBlock:^(QBResponse *response)
{
// error handling
NSLog(@"error: %@", response.error);
}];
}
- (void)loginWithQuickBloxChat:(NSString *)idandPassword {
QBUUser *selectedUser = [QBUUser user];
selectedUser.password = idandPassword;
selectedUser.login = idandPassword;
[ServicesManager.instance logInWithUser:selectedUser completion:^(BOOL success, NSString *errorMessage)
{
if (success)
{
[self getRecenetChatUsingInBadgeCount];
NSLog(@"Login in Quickblox");
[[NSUserDefaults standardUserDefaults]setObject:idandPassword forKey:@"QuickbloxIDPass"];
}
else
{
NSLog(@"Error in QuickBlox");
}
}];
}
CHATTING
Chatting with ChatViewController.
LOGOUT
1)Unsubscribed Device Token
NSString *deviceUdid = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
[QBRequest unregisterSubscriptionForUniqueDeviceIdentifier:deviceUdid successBlock:^(QBResponse *response) {
// Unsubscribed successfully
NSLog(@"Unsubscribed successfully");
} errorBlock:^(QBError *error) {
// Handle error
NSLog(@"Unsubscribed ERROR");
}];
2)ServicesManager Logout
[ServicesManager.instance logoutWithCompletion:^{
NSLog(@"logoutWithCompletion");
}];
3)logOut With Success Block
[QBRequest logOutWithSuccessBlock:^(QBResponse *response) {
// Successful logout
NSLog(@"Successful logout");
} errorBlock:^(QBResponse *response) {
// Handle error
NSLog(@"Logout ERROR %@",response);
}];
When Message send after logout and login again crash here
QMChatService.m
- (void)sendMessage:(QBChatMessage *)message
toDialogID:(NSString *)dialogID
saveToHistory:(BOOL)saveToHistory
saveToStorage:(BOOL)saveToStorage
completion:(QBChatCompletionBlock)completion
{
NSCParameterAssert(dialogID);
QBChatDialog *dialog = [self.dialogsMemoryStorage chatDialogWithID:dialogID];
NSAssert(dialog != nil, @"Dialog have to be in memory cache!");
[self sendMessage:message toDialog:dialog saveToHistory:saveToHistory saveToStorage:saveToStorage completion:completion];
}