Firebase not getting push token on first startup

Alexander Blohmé
1
Reputation point
Hello, do anyone knows why Firebase wont register with a push token the first time you start an app?
Heres my code:
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override void DidEnterBackground(UIApplication application)
{
Globals.ErIBakgrunn = true;
Console.WriteLine("[BG_MODE] (***) App entering background state.");
}
public override void WillEnterForeground(UIApplication application)
{
Globals.ErIBakgrunn = false;
Console.WriteLine("[BG_MODE] (***) App will enter foreground");
}
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
// Get current device token
var DeviceToken = deviceToken.Description;
//deviceToken.
if (!string.IsNullOrWhiteSpace(DeviceToken))
{
DeviceToken = DeviceToken.Trim('<').Trim('>');
}
// Get previous device token
var oldDeviceToken = NSUserDefaults.StandardUserDefaults.StringForKey("PushDeviceToken");
NSUserDefaults.StandardUserDefaults.SetString(DeviceToken, "PushDeviceToken");
Globals.FCM_TOKEN = Messaging.SharedInstance.FcmToken ?? "";
PKDebugger.ConsoleOutput("[TOKEN] (***) VI har token: " + Messaging.SharedInstance.FcmToken);
}
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public class CarIntegrationBridge
{
public static void Init()
{
}
}
public override void OnActivated(UIApplication uiApplication) {
}
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
MobileAds.SharedInstance.Start(CompletionHandler);
Xamarin.FormsMaps.Init();
Rg.Plugins.Popup.Popup.Init();
CarIntegrationBridge.Init();
List<string> adTestEnheter = new List<string>();
adTestEnheter.Add("62604a48fb5fb1e00e66202b148ba45b");
adTestEnheter.Add("GADSimulatorID");
PKDebugger.ConsoleOutput("(!!!) Device ID: " + UIDevice.CurrentDevice.IdentifierForVendor.ToString());
// CrossMTAdmob.Current.TestDevices = myStuffz;
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
var pushSettings = UIUserNotificationSettings.GetSettingsForTypes(
UIUserNotificationType.Alert
| UIUserNotificationType.Badge | UIUserNotificationType.Sound,
new NSSet());
UIApplication.SharedApplication.RegisterUserNotificationSettings(pushSettings);
UIApplication.SharedApplication.RegisterForRemoteNotifications();
}
else
{
UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
}
Firebase.Core.App.Configure();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
private void CompletionHandler(InitializationStatus status) { PKDebugger.ConsoleOutput("[ADS] (***) CompletionHandler is running..."); }
[Export("messaging:didReceiveRegistrationToken:")]
public void DidReceiveRegistrationToken(Messaging messaging, string fcmToken)
{
PKDebugger.ConsoleOutput($"Firebase registration token: {fcmToken}");
Globals.FCM_TOKEN = fcmToken;
}
}