Umar Ali Umar Ali - 4 years ago 242
iOS Question

FCM token get refreshed after some time

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}");
});
}

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download