Getting exception while integrating Firebase CloudMessaging into Xamarin.iOS project

1,051 views
Skip to first unread message

Implevista Development team

unread,
Dec 29, 2016, 10:22:18 AM12/29/16
to Firebase Google Group
Hi there,
I am strugling with a problem while integrating this firebase cloud messaging xamarin component https://components.xamarin.com/view/firebaseioscloudmessaging
into my xamarin.ios project. But I am getting two exceptions for these snippets of code below:

 // For iOS 10 display notification (sent via APNS)
 UNUserNotificationCenter.Current.Delegate = this;

// For iOS 10 data message (sent via FCM)
Messaging.SharedInstance.RemoteMessageDelegate = this;

here "this" can't be converted and getting exception like below:

Error CS0266 Cannot implicitly convert type 'Uno.iOS.AppDelegate' to 'Firebase.CloudMessaging.IMessagingDelegate'. An explicit conversion exists (are you missing a cast?)

Error CS0266 Cannot implicitly convert type 'Uno.iOS.AppDelegate' to 'UserNotifications.IUNUserNotificationCenterDelegate'. An explicit conversion exists (are you missing a cast?)


Can you suggest me how can I fix these two issues?

This is my code where integrating firebase cloud messaging:

public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        //
        // 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 override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            new SfChartRenderer();

            Firebase.Analytics.App.Configure();


            // Register your app for remote notifications.
            if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
            {
                /* TODO- will be enable for ios 10 later*/
                // iOS 10 or later
                var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
                UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) => {
                    Console.WriteLine(granted);
                });

                // For iOS 10 display notification (sent via APNS)
                UNUserNotificationCenter.Current.Delegate = this;

                // For iOS 10 data message (sent via FCM)
                Messaging.SharedInstance.RemoteMessageDelegate = this;

            }
            else
            {
                // iOS 9 or before
                var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
                var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null);
                UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
            }

            UIApplication.SharedApplication.RegisterForRemoteNotifications();
            Messaging.SharedInstance.Connect(error => {
                if (error != null)
                {
                    // Handle if something went wrong while connecting
                }
                else
                {
                    // Let the user know that connection was successful
                }
            });

            var token = InstanceId.SharedInstance.Token;
            // Monitor token generation
            InstanceId.Notifications.ObserveTokenRefresh((sender, e) => {
                // Note that this callback 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;

                // Do your magic to refresh the token where is needed
            });


            LoadApplication(new App());

            return base.FinishedLaunching(app, options);
        }

Krati Chauhan

unread,
Jul 31, 2017, 11:28:32 AM7/31/17
to Firebase Google Group
Found this link which solved my problem and sharing here for the sake of ppl who reach this discussion first before finding a solution

Reply all
Reply to author
Forward
0 new messages