xamarin / GoogleApisForiOSComponents

MIT License
225 stars 162 forks source link

Messaging.SharedInstance.AutoInitEnabled doesn't work as expected #545

Open lbulegato opened 2 years ago

lbulegato commented 2 years ago

In Xamarin.Firebase.Messaging version 122.0.0.3 (latest stable)

If you delete a token with the following code, and Messaging.SharedInstance.AutoInitEnabled = true;

Messaging.SharedInstance.DeleteToken(new MessagingDeleteFcmTokenCompletionHandler((error) =>
{
    if (error != null)
        Logger.Info($"DeleteToken error=[{error.LocalizedDescription}]");                
}));

TheDidReceiveRegistrationToken(Messaging messaging, string fcmToken) is called 2 times:

so it seems that Messaging.SharedInstance.AutoInitEnableddoesn't restore the token, but if you do this change:

Messaging.SharedInstance.AutoInitEnabled = false;
Messaging.SharedInstance.DeleteToken(new MessagingDeleteFcmTokenCompletionHandler((error) =>
{
    if (error != null)
        Logger.Info($"DeleteToken error=[{error.LocalizedDescription}]");

    Messaging.SharedInstance.AutoInitEnabled = true;
}));

The DidReceiveRegistrationToken(Messaging messaging, string fcmToken) is called 2 times, with the expected order

Just a plus, if you try the deprecated method

InstanceId.SharedInstance.DeleteId(new InstanceIdDeleteHandler((error) =>
{
    if (error != null)
        Logger.Info($"DeleteId error=[{error.LocalizedDescription}]");
}));

You don't need to fake the Messaging.SharedInstance.AutoInitEnabled and the sequence of calls for The DidReceiveRegistrationToken(Messaging messaging, string fcmToken) is right.