我認爲你必須建立一個後端服務。一種方法可能是用Node JS構建一個Rest Api。你可以定義像邀請用戶這樣的路線,它需要一個用戶ID和組ID。在路由功能中,您可以將組ID添加到用戶ID後面的用戶的邀請中。其他路線可以是接受邀請,您可以在其中發送用戶ID和組ID。在該功能中,您檢查用戶是否有該組的邀請,以及他是否將他添加到組中。但這只是近千種可能方式的建議。你也可以在你的應用程序中添加這些功能。而不是使用我上面提到的API函數作爲API路徑,直接讓它們在應用程序中。但是,如果數據庫中存在新的邀請記錄,那麼您必須通知用戶可能使用推送通知。但我會建議建立一個小服務器。
可以看看這裏一個基本的休息mSQL的節點JS教程https://codeforgeek.com/2015/01/nodejs-mysql-tutorial/你會在這裏這樣定義
function inviteUser(req,res) {
pool.getConnection(function(err,connection){
if (err) {
connection.release();
res.json({"code" : 100, "status" : "Error in connection database"});
return;
}
console.log('connected as id ' + connection.threadId);
connection.query("select req.body.userId from user",function(err,rows){
connection.release();
if(!err) {
//ADD Group id to the user access the id with req.body.groupId
res.json(rows);
}
});
connection.on('error', function(err) {
res.json({"code" : 100, "status" : "Error in connection database"});
return;
});
});
}
function acceptInvitation(req,res){
pool.getConnection(function(err,connection){
if (err) {
connection.release();
res.json({"code" : 100, "status" : "Error in connection database"});
return;
}
console.log('connected as id ' + connection.threadId);
connection.query("select req.body.groupId from groups",function(err,rows){
connection.release();
if(!err) {
//ADD user id to the group access the id with req.body.userId
res.json(rows);
}
});
connection.on('error', function(err) {
res.json({"code" : 100, "status" : "Error in connection database"});
return;
});
});
}
}
app.get("https://stackoverflow.com/users/invite",function(req,res){-
inviteUser(req,res);
});
app.get("https://stackoverflow.com/users/accept",function(req,res){-
acceptInvitation(req,res);
});
路線從應用程序,你會在你的服務器的URL發送HTTP請求像http://localhost:8080/users/invite與{用戶id的身體: xxxxx,groupId:xxxxx}
我很感謝你的回答,它給了我一些研究。我一直在研究一兩天,而不是提出任何看起來可行的事情。 –
我加了一些提示可能會幫助你,對不起我的英文不好 – Sprotte
不用擔心我很欣賞幫助 –