Closed ksoftllc closed 11 months ago
same issue happen mine too, could help any one?
Update: I found this link that explained how to get the CLIENT_ID to generate in the plist file: https://stackoverflow.com/a/77235721/1256015.
Now I get a different null pointer exception:
Object reference not set to an instance of an object. - at Plugin.Firebase.CloudMessaging.FirebaseCloudMessagingImplementation.GetTokenAsync()
This is the code that is throwing:
public Task<string> GetTokenAsync()
{
var token = Messaging.SharedInstance.FcmToken;
return string.IsNullOrEmpty(token) ? throw new FirebaseException("Couldn't retrieve FCM token") : Task.FromResult(token);
}
Since I am not getting the FirebaseException
, I have to conclude that Messaging.SharedInstance
is null. The call to CrossFirebase.Initialize(...)
is not throwing, so why is the shared instance null?
I got this working on my Apple device. The issue for me was calling GetTokenAsync()
before CrossFirebase.Initialize(...)
. In my case, I had added the call to GetTokenAsync()
to App.xaml.cs which was executing before iOS.FinishedLaunching
event. For me, I resolved it by changed to iOS.WillFinishLaunching
event. Could also have moved the GetTokenAsync()
call site to occur later in the app startup.
This code from your plugin crashes with null pointer exception:
My GoogleService-Info.plist file from FCM console does not have a CLIENT_ID key. Here is the redacted file:
I have recreated the file a couple of times and it never comes with a CLIENT_ID key.
Here is my code:
Here is the stack trace:
How do I initialize for iOS?