简体   繁体   中英

Send message to dialog iOS Quickblox

I have this in AppDelegate.m

[QBSettings setApplicationID:xxxxxx];
    [QBSettings setAuthKey:@"dsad"];
    [QBSettings setAuthSecret:@"asdd"];
    [QBSettings setAccountKey:@"asdsda"];
    [QBSettings setLogLevel:QBLogLevelNothing];

    [QBRequest logInWithUserLogin:@"testuser" password:@"testuser" successBlock:^(QBResponse *response, QBUUser *user) {
        if (user) {
            user.login = @"testuser";
            user.password = @"testuser";
            // __typeof(self) strongSelf = weakSelf;
           [[QBChat instance] connectWithUser:user completion:^(NSError * _Nullable error) {
}
             ];
        }
    } errorBlock:^(QBResponse * _Nonnull response) {

    }];

and this trying to send a message in another ViewController.m

 QBChatMessage *messagetosend = [QBChatMessage message];
    messagetosend.senderID = 10516336;
    messagetosend.senderNick = @"Andrey M.";
    messagetosend.text = @"test test";
    messagetosend.dateSent = [NSDate dateWithTimeInterval:-12.0f sinceDate:[NSDate date]];

    QBChatDialog *chatDialog = [[QBChatDialog alloc] initWithDialogID:@"56d9e95ba28f9a7bf5000058" type:QBChatDialogTypePublicGroup];

    [chatDialog joinWithCompletionBlock:^(NSError * _Nullable error) {
        [chatDialog sendMessage:messagetosend completionBlock:^(NSError * _Nullable error) {
            NSLog(@"%@",[error localizedDescription]);
        }];

    }];

but the message doesn't sent to the dialog I check in quickblox dashboard it doesn't work. I used PHP framework and it works but in the iOS i do not know where it the problem, must open a session or what ?

FYI: this dialog ID " 56d9e95ba28f9a7bf5000058 " from Quickblox dashboard it isn't randomly or fake

Thanks

In order to send message in group chat dialog you should create dialog on a server.

Dialog must contain occupantIDs

+ (QB_NONNULL QBRequest *)createDialog:(QB_NONNULL QBChatDialog *)dialog
                          successBlock:(QB_NULLABLE void(^)(QBResponse * QB_NONNULL_S response, QBChatDialog * QB_NULLABLE_S createdDialog))successBlock
                            errorBlock:(QB_NULLABLE QBRequestErrorBlock)errorBlock;

You must send custom parameters

messagetosend.senderID = 10516336;
messagetosend.senderNick = @"Andrey M.";
messagetosend.text = @"test test";
/** You will see the on dashboard after you set save_to_history to true **/
messagetosend.customParameters = ["application_id":kQBApplicationID, "save_to_history":true]

Let me know if this works for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM