Forum Xamarin Xamarin.iOS

GoogleApisForiOSComponents, CloudMessaging sample -- Messaging.SharedInstance always null

patcarutherspatcaruthers USMember ✭✭✭

I have implemented my apps AppDelegate.cs following the AppDelegate.cs in the sample, however when i run it Messaging.SharedInstance is null. Does anyone know where/how that instance is supposed to be created?


  • Pedro_PazPedro_Paz Member ✭✭

    Same problem here. Im using Xamarin.Firebase.IOS.CloudMessaging version

  • azamabdulrahimazamabdulrahim Member

    Call this first:

  • odinhausodinhaus Member ✭✭
    edited July 29

    I have the same issue, and I am calling App.Configure() first.

    I actually am using the AppDelegate class as presented in GoogleApisForiOSComponents CloudMessaging samples

    Both of these SharedInstance instances are null:

    Firebase.CloudMessaging.Messaging.SharedInstance.Delegate = this;

    I'm pretty dead in the water if the component author's own sample code won't work.

    Im on latest VS 2019, Latest XCode on build system, and am deploying to an actual iOS iPhone (not a simulator).

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
                NotificationSink = Xamarin.Forms.DependencyService.Get<Mobile.Services.INotificationSink>();
                LoadApplication(new App());
                // Register your app for remote notifications.
                if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
                    // For iOS 10 display notification (sent via APNS)
                    UNUserNotificationCenter.Current.Delegate = this;
                    var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
                    UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) => {
                    // iOS 9 or before
                    var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
                    var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null);
                Firebase.CloudMessaging.Messaging.SharedInstance.Delegate = this;
                return true;
  • xamarinzeroxamarinzero Member ✭✭

    Did anyone figure out why Messaging.SharedInstance always null?
    In my case, Messaging.SharedInstance is NOT null on simulator...FCM token gets created.
    On the device it is always null. So app crashes at Messaging.SharedInstance.Delegate = this;

    Please let me know if you found the solution. thanks.

  • xamarinzeroxamarinzero Member ✭✭

    I tried the solution by JoshuaTanton in the following link, but that didnt help me.

  • xamarinzeroxamarinzero Member ✭✭

    When I run the same code against the simulator it runs ok. Messaging.SharedInstance is not null.
    I am not sure if that says something....

Sign In or Register to comment.