Firebase Analytics : The call is ambiguous between the following methods or properties

JassimRahmaJassimRahma USMember ✭✭✭

Hi,

Why I keep getting this error in my Xamarin Forms iOS project and how to fix it please?

The call is ambiguous between the following methods or properties: 'Analytics.LogEvent(string, NSDictionary<NSString, NSObject>)' and 'Analytics.LogEvent(string, Dictionary<object, object>)'

for this code [on line Analytics..LogEvent(eventId, null);]

using System;
using Xamarin.Forms;
using System.Collections.Generic;
using System.Text;
using Firebase.Analytics;
using Firebase.Core;
using Foundation;
using Jafaria;
using Jafaria.iOS;

[assembly: Xamarin.Forms.Dependency(typeof(GoogleFirebaseAnalytics))]
namespace Jafaria.iOS
{
    public class GoogleFirebaseAnalytics : IFirebaseAnalytics
    {

        public void FirebaseLogEvent(string eventId)
        {
            LogEvent(eventId, (IDictionary<string, string>)null);
        }

        /*
        public void LogEvent(string eventId, string paramName, string value)
        {
            LogEvent(eventId, new Dictionary<string, string>
            {
                { paramName, value }
            });
        }
        */

        public void LogEvent(string eventId, IDictionary<string, string> parameters)
        {
            if (parameters == null)
            {
                Analytics..LogEvent(eventId, null);
                return;
            }

            var keys = new List<NSString>();
            var values = new List<NSString>();
            foreach (var item in parameters)
            {
                keys.Add(new NSString(item.Key));
                values.Add(new NSString(item.Value));
            }

            var parametersDictionary =
                NSDictionary<NSString, NSObject>.FromObjectsAndKeys(values.ToArray(), keys.ToArray(), keys.Count);
            Analytics.LogEvent(eventId, parametersDictionary);

        }
    }
}

Best Answer

Answers

  • JassimRahmaJassimRahma USMember ✭✭✭

    How can I implement the Firebase crashes here?

  • NirajBhattNirajBhatt Member ✭✭

    Hi @JassimRahma ,
    were you able to fix this issue? could you please share code if you have fixed issue? I am facing similar issue and even after fixing this, I am not able to push custom events to Firebase for iOS.
    My issue link: https://forums.xamarin.com/discussion/145584/not-able-to-push-custom-events-in-firebase-analytics#latest

Sign In or Register to comment.