我已经开发了一个iOS应用程序,使用Xamarin和集成的FCM (Firebase消息传递)来进行推送通知。它在开发阶段很好,但在测试飞行测试中,FCM令牌在一段时间后会自动重新生成或刷新(在5-10分钟之间)。
void TokenRefreshNotification(object sender, NSNotificationEventArgs e)
{
// This method will be fired everytime a new token is generated, including the first
// time. So if you need to retrieve the token as soon as it is available this is where that
// should be done.
//var refreshedToken = InstanceId.SharedInstance.Token;
var token = InstanceId.SharedInstance.Token;
WriteLog("Token Refresh");
ConnectToFCM();
// TODO: If necessary send token to application server.
}
public static void ConnectToFCM()
{
Messaging.SharedInstance.Connect(error =>
{
if (InstanceId.SharedInstance.Token != null)
{
var token = InstanceId.SharedInstance.Token;
// FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Unknown)
// ApnsTokenType = ApnsTokenType.Unknown;
if (!Settings.DeviceId.Equals(token))
{
Settings.DeviceId = token;
Console.WriteLine("Token Updated");
}
}
Console.WriteLine($"Token: {InstanceId.SharedInstance.Token}");
});
}发布于 2017-02-02 04:57:30
解决了。我的观察是来自同一个API 2,安装了不同的应用程序,导致了这个问题。当我卸载一个应用程序(前一个应用程序只有不同的包ID )时,现在它可以正常工作了。几分钟后没有令牌自动刷新。
https://stackoverflow.com/questions/41628764
复制相似问题