目前,我要求我必须为不同类型的用户订阅不同的主题。 用例是,如果多个用户从单个设备登录,则根据登录用户的角色订阅和取消订阅主题的方法是什么。 一个快速的解决方案是取消订阅所有主题,然后订阅适当的主题。
假设user3已登录到应用程序。取消订阅所有主题。
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <ctime>
void MainWindow::CmdCheckNewClicked() {
if(result != -1) {
int eingabe = ui->EdtInput->text().toInt();
QString comment;
if(eingabe==result) {
comment = "Right";
} else {
comment = "Wrong";
}
comment += QString(": %1 + %2 = %3").arg(a).arg(b).arg(result);
ui->LblComment->setText(comment);
ui->EdtInput->setText("");
}
a = rand() % 20 + 20;
b = rand() % 20 + 20;
result = a + b;
QString task = QString("%1 + %2").arg(a).arg(b);
ui->LblTask->setText(task);
ui->EdtInput->setFocus();
}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
ui(new Ui::MainWindow) {
ui->setupUi(this);
srand((unsigned)time(NULL));
connect(ui->CmdCheckNew, SIGNAL(clicked()),
SLOT(CmdCheckNewClicked()));
connect(ui->CmdQuit, SIGNAL(clicked()), SLOT(close()));
}
MainWindow::~MainWindow() {
delete ui;
}
然后订阅适当的。
FirebaseMessaging.getInstance().unsubscribeFromTopic("Topic1");
FirebaseMessaging.getInstance().unsubscribeFromTopic("Topic2");
FirebaseMessaging.getInstance().unsubscribeFromTopic("Topic3");
我不确定这是解决此问题的最佳方案。有人有更好的方法吗?请帮我。提前致谢
答案 0 :(得分:0)
您的方法是正确的,在用户注销时取消订阅,并在新用户登录时再次订阅。