I am able to create group dialog box as I found this code:
chatDialog = [[QBChatDialog alloc] initWithDialogID:#"dialogueid" type:QBChatDialogTypeGroup];
chatDialog.name = #" Bob, Sam, Garry";
chatDialog.occupantIDs = #[#(1)];
[QBRequest createDialog:chatDialog successBlock:^(QBResponse *response, QBChatDialog *createdDialog) {
} errorBlock:^(QBResponse *response) {
}];
but when I try to change type to QBChatDialogTypePrivate.
Dialog is not creating and can you please tell me what is dialog id and where to find it?
Just init your QBChatDialog with ID nil, server will set it for you and createdDialog that is returned by QBRequest will have correct dialogID.
QBChatDialog *chatDialog = [[QBChatDialog alloc] initWithDialogID:nil type:QBChatDialogTypePrivate];
chatDialog.occupantIDs = #[#(opponentID)];
[QBRequest createDialog:chatDialog successBlock:^(QBResponse *response, QBChatDialog *createdDialog) {
NSLog(#"Created dialog: %#", createdDialog);
} errorBlock:^(QBResponse *response) {
NSLog(#"Failed to create dialog with error: %#", response.error);
}];
Related
I've integrated quickblox in my app. as I fetched all user in tableview using this code
QBGeneralResponsePage *page = [QBGeneralResponsePage responsePageWithCurrentPage:1 perPage:100];
[QBRequest usersForPage:page successBlock:^(QBResponse *response, QBGeneralResponsePage *pageInformation, NSArray *users)
{
[_NameArray addObjectsFromArray:users];
}
errorBlock:^(QBResponse *response)
{
}];
}
errorBlock:^(QBResponse *response)
{
NSLog(#"error: %#", response.error);
}];
in _nameArray I've all user information in QBUUSER object form
QBUUser *obj = [Array objectAtIndex:indexPath.row];
NSString *name = obj.fullname;
in retrieve all user. now when loginUser click on particular contact or retrieve user then i create private group one to one communication using this code
-(void)chat
{
chatDialog = [[QBChatDialog alloc] initWithDialogID:NULL type:QBChatDialogTypePrivate];
chatDialog.occupantIDs = #[#(chatuserobj.ID)];
[QBRequest createDialog:chatDialog successBlock:^(QBResponse *response, QBChatDialog *createdDialog) {
} errorBlock:^(QBResponse *response) {
}];
}
and main thing send and receive message in that view controller i have taken textfield for sending message and table view for show message for sending message i have used this code
-(void)startChat
{
[[QBChat instance] addDelegate:self];
QBChatMessage *message = [QBChatMessage message];
[message setText:#"Hey there"];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[#"save_to_history"] = #YES;
[message setCustomParameters:params];
[chatDialog sendMessage:message completionBlock:^(NSError * _Nullable error)
{
NSLog(#"Message sent");
}];
}
and used below delegate method
- (void)chatDidReceiveMessage:(QBChatMessage *)message
I actually see the private group in admin panel of quickblox but don't see the sent message. please help me.
Instead of you're code like:
[chatDialog sendMessage:message completionBlock:^(NSError * _Nullable error)
{
NSLog(#"Message sent");
}];
Use the following code:
[QBRequest createMessage:message successBlock:^(QBResponse *response, QBChatMessage *createdMessage) {
NSLog(#"success: %#", createdMessage);
} errorBlock:^(QBResponse *response) {
NSLog(#"ERROR: %#", response.error);
}];
I use Code like:
#pragma mark Tool bar Actions
- (void)didPressSendButton:(UIButton *)button
withMessageText:(NSString *)text
senderId:(NSUInteger)senderId
senderDisplayName:(NSString *)senderDisplayName
date:(NSDate *)date {
[[QBChat instance] addDelegate:self];
QBChatMessage *message = [QBChatMessage message];
[message setText:text];
message.senderID = senderId;
message.recipientID= [[NSUserDefaults standardUserDefaults] integerForKey:#"CurrentRecipientID"];
message.dateSent = [NSDate date];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[#"save_to_history"] = #YES;
[message setCustomParameters:params];
[QBRequest createMessage:message successBlock:^(QBResponse *response, QBChatMessage *createdMessage) {
NSLog(#"success: %#", createdMessage);
[self.chatSectionManager addMessage:createdMessage];
} errorBlock:^(QBResponse *response) {
NSLog(#"ERROR: %#", response.error);
}];
[self finishSendingMessageAnimated:YES];
}
I know this question has been asked multiple time but none of them solved my problem.
Error Domain=com.quickblox.chat Code=401 "Password not verified"
actually I have tried this:
- (void)viewDidLoad
{
[super viewDidLoad];
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(#"bdsfbd %#",chatuserobj.fullName);
NSLog(#"Chat Id %lu",(unsigned long)chatuserobj.ID);
NSLog(#"Current User %#",[QBSession currentSession].currentUser);
QBUUser *currentUserr = [QBUUser user];
currentUserr.ID = appDelegate.loginUserId;
currentUserr.password = appDelegate.loginUserPassword;
// connect to Chat
[QBRequest logInWithUserLogin:appDelegate.loginUser password:appDelegate.loginUserPassword successBlock:^(QBResponse *response, QBUUser *user)
{
chatDialog = [[QBChatDialog alloc] initWithDialogID:NULL type:QBChatDialogTypePrivate];
chatDialog.occupantIDs = #[#(chatuserobj.ID)];
[QBRequest createDialog:chatDialog successBlock:^(QBResponse *response, QBChatDialog *createdDialog)
{
NSLog(#"Created Dialog %#",createdDialog);
} errorBlock:^(QBResponse *response)
{
NSLog(#"Error %#",response);
}];
} errorBlock:^(QBResponse *response) {
}];
[[QBChat instance] connectWithUser:chatuserobj completion:^(NSError * _Nullable error)
{
NSLog(#"USer is Connected %#",error.description);
[self startChat];
}];
[QBSettings setKeepAliveInterval:30];
[QBSettings setAutoReconnectEnabled:YES];
}
and this
-(void)startChat
{
[[QBChat instance] addDelegate:self];
QBChatMessage *message = [QBChatMessage message];
[message setText:#"Hey there"];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[#"save_to_history"] = #YES;
[message setCustomParameters:params];
[chatDialog sendMessage:message completionBlock:^(NSError * _Nullable error)
{
NSLog(#"Completed: %#",error.description);
}];
}
I don't know where I am wrong. So point out my mistake.
EDIT: again in did load
- (void)viewDidLoad
{
[super viewDidLoad];
// connect to Chat
[[QBChat instance] connectWithUser:currentUserr completion:^(NSError * _Nullable error)
{
NSLog(#"USer is Connected %#",error.description);
}];
dispatch_async(dispatch_get_main_queue(), ^(void)
{
[self chat];
});
dispatch_async(dispatch_get_main_queue(), ^(void)
{
[self startChat];
});
}
chat is method for creating dialog for private group or one to one connection
-(void)chat
{
chatDialog = [[QBChatDialog alloc] initWithDialogID:NULL type:QBChatDialogTypePrivate];
chatDialog.occupantIDs = #[#(chatuserobj.ID)];
[QBRequest createDialog:chatDialog successBlock:^(QBResponse *response, QBChatDialog *createdDialog) {
} errorBlock:^(QBResponse *response) {
}];
}
and start chat actual communication occur
-(void)startChat
{
[[QBChat instance] addDelegate:self];
QBChatMessage *message = [QBChatMessage message];
[message setText:#"Hey there"];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[#"save_to_history"] = #YES;
[message setCustomParameters:params];
[chatDialog sendMessage:message completionBlock:^(NSError * _Nullable error)
{
NSLog(#"Completed: %#",error.description);
}];
}
now this error occur
UserInfo={NSLocalizedRecoverySuggestion = You are not connected to chat.
- (void)viewDidLoad
{
[super viewDidLoad];
// connect to Chat
[[QBChat instance] connectWithUser:currentUserr completion:^(NSError * _Nullable error)
{
NSLog(#"USer is Connected %#",error.description);
dispatch_async(dispatch_get_main_queue(), ^(void)
{
[self chat];
});
dispatch_async(dispatch_get_main_queue(), ^(void)
{
[self startChat];
});
}];
}
and same method of start chat and chat. it works well
[[QBChat instance] connectWithUser:chatuserobj completion:^(NSError * _Nullable error)
{
NSLog(#"USer is Connected %#",error.description);
}];
This method is used to connect yourself to the chat and not your opponents. Furthermore, in order to connect with this method your QBUUser instance must have valid password set as password property.
Basically you need to connect yourself to the chat and then just start creating dialogs and sending messages.
I have a requirement,Lets say there are 3-Users for my app. I want to add an image(Profile pic purpose) to each user so that this image can be visible to other two users who are using the same app. Just like whatsapp profile pics. So for this purpose I did the following things.
Step 1 : Logged in as User1
then I added this code to upload image file. After I logged in with User1 credentials and I made Public property as YES while uploading file.
NSData *imageData = UIImagePNGRepresentation([UIImage imageNamed:#"arrow.png"]);
[QBRequest TUploadFile:imageData fileName:#"arrow.png" contentType:#"image/png" isPublic:YES successBlock:^(QBResponse *response, QBCBlob *blob) {
} statusBlock:^(QBRequest *request, QBRequestStatus *status) {
} errorBlock:^(QBResponse *response) {
}];
Step 2 : Logged in as User2
Then I did like this I'm fetching all the users belongs to my app. using
QBGeneralResponsePage *responsePage = [QBGeneralResponsePage responsePageWithCurrentPage:currentPage perPage:perPage];
[QBRequest usersForPage:responsePage successBlock:^(QBResponse *response, QBGeneralResponsePage *page, NSArray *users) {
weakSelf.allUsers = [users mutablecopy]
[weakSelf.tableView reloadData];
} errorBlock:^(QBResponse *response) {
}];
Step 3 :
Now I have all the users so I'm doing iteration to find the users blob id .
QBUUser *user = (QBUUser *)self.allUsers[indexPath.row];
if (user.blobID != 0) {
[QBRequest downloadFileWithID:user.blobID successBlock:^(QBResponse *response, NSData *fileData) {
UIImage *img=[UIImage imageWithData:fileData];
[cell.imageView setImage:img];
} statusBlock:^(QBRequest *request, QBRequestStatus *status) {
} errorBlock:^(QBResponse *response) {
}];
}
But the problem is here I'm not getting any blobID with the User1 means blobID of user1 as 0(all users blobID as 0), But while uploading it was success and I got blobID after uploading the file using User1 as logged in.
But when I logged in as user2 or User3 it is not showing any blobID associated with user1. And I made Public as Yes while uploading.
Is this correct way of doing or any mistake I'm doing please let me know ?
You should update user's blobID using request with QBUpdateUserParameters after blob's uploading:
[QBRequest TUploadFile:imageData fileName:#"arrow.png" contentType:#"image/png" isPublic:YES successBlock:^(QBResponse *response, QBCBlob *blob) {
QBUpdateUserParameters *userParams = [QBUpdateUserParameters new];
userParams.blobID = blob.ID;
[QBRequest updateCurrentUser:userParams successBlock:^(QBResponse * _Nonnull __unused response, QBUUser * _Nullable user) {
} errorBlock:^(QBResponse * _Nonnull response) {
}];
} statusBlock:^(QBRequest *request, QBRequestStatus *status) {
} errorBlock:^(QBResponse *response) {
}];
Here is an example of how I retrieve objects of a custom class from Quickblox:
[QBRequest objectsWithClassName:#"My_Custom_Class" extendedRequest:getRequest successBlock:^(QBResponse *response, NSArray *objects, QBResponsePage *page) {
// Success
} errorBlock:^(QBResponse *response) {
// Error
}];
Here is an example of how I create new objects for a custom class in Quickblox:
QBCOCustomObject *object = [QBCOCustomObject customObject];
object.className = #"My_Custom_Class";
// Object fields
[object.fields setObject:self.titleTextView.text forKey:#"Title"];
[object.fields setObject:self.bodyTextView.text forKey:#"Body"];
[object.fields setObject:self.userSession.fullName forKey:#"Author_Name"];
[object.fields setObject:#"self.username" forKey:#"Author_Username"];
[QBRequest createObject:object successBlock:^(QBResponse *response, QBCOCustomObject *object) {
// Response
} errorBlock:^(QBResponse *response) {
// Error
}];
I need to be able to get the status/progress of these, so that I can show a loading/progress bar to my users based on actual progress made.
How can I do this?
There is no Statusblock callback for these two methods. You can just show an activity indicator to show the progress.
I have a question regarding Quick blox API. Right now I am sign up an user using below code.
[QBRequest createSessionWithSuccessBlock:^(QBResponse *response, QBASession *session) {
// session created
QBUUser *user = [QBUUser user];
user.password = userPasswordTextField.text;
user.login = userNameTextField.text;
user.fullName = userRealNameTextField.text;
user.email = userEmailTextField.text;
// Registration sign up of User
[QBRequest signUp:user successBlock:^(QBResponse *response, QBUUser *user) {
[QBRequest createSessionWithSuccessBlock:^(QBResponse *response, QBASession *session) {
NSLog(#"checkingl registering");
[QBRequest userWithLogin:user.login successBlock:^(QBResponse *response, QBUUser *user) {
NSLog(#"checkingl updatingqb");
} errorBlock:^(QBResponse *response) {
// Handle error
}];
}errorBlock:^(QBResponse *response) {
// Handle error
}];
} errorBlock:^(QBResponse *response) {
// Handle error here
NSLog(#"error while signing up with QB");
NSLog(#"fail sign Up %#",response);;
[self showAlert:nil message:#"User with login that has already been taken" cancelButtonTitle:nil otherButtonTitle:#"OK"];
return ;
}];
} errorBlock:^(QBResponse *response) {
// handle errors
NSLog(#" error in creating session %#", response.error);
}];
In above code first I am creating a session and sign up an new user, then I am login user. At sign up time I did't log in user for QuickBlox Chat at signup time, But later when I will log in into Quick blox chat in another module, still I have to create new session or I have to maintain new session.
Any session will remain valid for 2 hours after the last request to QuickBlox. To check a session's expiration date use this next snippet of code:
NSDate *sessionExpiratioDate = [QBBaseModule sharedModule].tokenExpirationDate;
NSDate *currentDate = [NSDate date];
NSTimeInterval interval = [currentDate timeIntervalSinceDate:tokenExpirationDate];
if(interval > 0){
// recreate session here
}
Check this guide. This feature is available since 1.8 iOS SDK.
Reference: Igor Khomenko