简体   繁体   English

将消息发送到对话框iOS Quickblox

[英]Send message to dialog iOS Quickblox

I have this in AppDelegate.m 我在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 这试图在另一个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. 但是消息没有发送到我在quickblox仪表板中签到的对话框中,它不起作用。 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 ? 我使用PHP框架,并且可以工作,但是在iOS中,我不知道问题出在哪里,必须打开一个会话或什么?

FYI: this dialog ID " 56d9e95ba28f9a7bf5000058 " from Quickblox dashboard it isn't randomly or fake 仅供参考:来自Quickblox信息中心的对话框ID“ 56d9e95ba28f9a7bf5000058”不是随机的或伪造的

Thanks 谢谢

In order to send message in group chat dialog you should create dialog on a server. 为了在群聊对话框中发送消息,您应该在服务器上创建对话框。

Dialog must contain occupantIDs 对话框必须包含occupantID

+ (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. 让我知道这是否适合您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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