在令牌刷新时,生成刷新令牌并在应用程序安装时存储在数据库中。
令牌生成代码:
[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);
}}
答案 0 :(得分:0)
您可以使用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();
}
}