【问题标题】:Store the Firebase token in database将 Firebase 令牌存储在数据库中
【发布时间】:2018-11-12 07:20:54
【问题描述】:

在安装应用程序时,在令牌刷新时生成刷新令牌并存储在数据库中。

令牌生成代码:

[Service]

[IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
public class MyFirebaseIIDService : FirebaseInstanceIdService 
{
    const string TAG = "MyFirebaseIIDService";
    //string refreshedToken;
    private HttpClient client = new HttpClient();

    public override void OnTokenRefresh()
    {

       var refreshedToken = FirebaseInstanceId.Instance.Token;
       Log.Debug(TAG, "Refreshed token: " + refreshedToken);
        SendRegistrationToServer(refreshedToken);            
    }}

【问题讨论】:

  • 问题是什么?
  • 本地SQLite数据库是哪个数据库?还是您需要使用某些 API 将其推送到服务器?
  • 您需要将令牌连同用户 ID 等任何其他详细信息推送到您的服务器。
  • 只在sql server中存储token。只有在安装应用程序时才在sql server中添加token。但是每次启动该应用程序时都不会将其存储在 Sql Server 上。是的,我需要将其推送到服务器。

标签: firebase xamarin.forms xamarin.android firebase-cloud-messaging


【解决方案1】:

您可以使用SendRegistrationToServer() 方法中的SqlConnection 类连接到您的sql server。

例如:

    void SendRegistrationToServer(string token)
    {
        using (SqlConnection connection = new SqlConnection(yourconnectionString))
        {
            SqlCommand command = new SqlCommand("INSERT INTO table1 (id, token) VALUES('1', '" + token + "')", connection);
            command.Connection.Open();
            command.ExecuteNonQuery();
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-23
    • 1970-01-01
    • 2021-08-15
    • 2017-10-30
    • 2017-12-25
    • 1970-01-01
    • 2020-03-15
    • 1970-01-01
    相关资源
    最近更新 更多