在 iOS 共享扩展中使用 QuickBlox 的推荐流程是什么

What is the recommended Process for using QuickBlox in iOS Share Extension

我在主 iOS 应用程序中成功使用了 QuickBlox,并希望使用 cocoapod 'QuickBlox','~> 2.7.5' 将功能扩展到共享扩展中。我需要在不打开主应用程序的情况下在后台发送消息。

我使用下面的代码首次设置仅发送文本但没有成功。

    [QBRequest logInWithUserLogin:USERNAME password:PASSWORD successBlock:^(QBResponse *response, QBUUser *user) {
        if (user) {
            user.login = USERNAME;
            user.password = PASSWORD;
            [[QBChat instance] connectWithUser:user completion:^(NSError * _Nullable error) {

                QBChatDialog *chatDialog = [[QBChatDialog alloc] initWithDialogID:[settingsDict valueForKey:@"sendingID"] type:QBChatDialogTypeGroup];

                QBChatMessage *messagetosend = [QBChatMessage message];
                messagetosend.senderID = userQBID;
                messagetosend.text = self.contentText;
                messagetosend.dateSent = [NSDate dateWithTimeInterval:-12.0f sinceDate:[NSDate date]];

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

                }];
            }
             ];
        }
    } errorBlock:^(QBResponse * _Nonnull response) { }];

您可以通过 REST 发送消息。通过 REST 发送不需要连接到聊天和加入对话。

NSUInteger senderID = //Current User ID
QBChatMessage *message = [QBChatMessage message];
message.text = intent.content;
message.senderID = senderID;
message.markable = YES;
message.deliveredIDs = @[@(senderID)];
message.readIDs = @[@(senderID)];
message.dialogID = dialogID;
message.dateSent = [NSDate date];

[QBRequest sendMessage:message successBlock:^(QBResponse * _Nonnull response, QBChatMessage * _Nonnull createdMessage) {

} errorBlock:^(QBResponse * _Nonnull response) {

}];