Reputation: 145
I have developed an iOS App using Xamarin and integrated FCM (Firebase Cloud Messaging) for push notifications. Its working fine on development phase, but on beta testing through test flight, the FCM token automatically regenerates or refreshes after some time (in between 5-10 minutes).
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}");
});
}
Upvotes: 1
Views: 1697
Reputation: 145
Solved. My Observation is from same API 2 different App is installed that's causing the problem. When i uninstalled one App(which is previous one only bundle ID is different) now its working fine. No token refreshed automatically after few minutes.
Upvotes: 1