Firebase名称:com.firebase.core原因:配置失败。这可能是由无效的GOOGLE_APP_ID引起的

时间:2018-02-09 20:49:28

标签: firebase xamarin xamarin.ios

按照https://components.xamarin.com/gettingstarted/firebaseioscloudmessaging中firebase指令集入门中的说明调用Firebase.Core.App.Configure() 导致错误如下所示。我已经看到了其他答案,但它们似乎特别适用于cordova和GoogleServices-Info.plist被破坏或未被复制到特定文件夹。

错误

  

名称:com.firebase.core原因:配置失败。它可能是造成的   由GoogleService-Info.plist中的无效GOOGLE_APP_ID设置或在   定制选项。

Nuget

调用Firebase.Core.App.Configure();

时出错
 private void RegisterForPushNotifications()
    {

        if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
        {
            // iOS 10
            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;
        }
        else
        {
            // iOS 9 <=
            var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
            var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null);
            UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
        }

        UIApplication.SharedApplication.RegisterForRemoteNotifications();

        // Firebase component initialize
        Firebase.Core.App.Configure();


        Firebase.InstanceID.InstanceId.Notifications.ObserveTokenRefresh((sender, e) =>
        {
            var newToken = Firebase.InstanceID.InstanceId.SharedInstance.Token;

            // if you want to send notification per user, use this token
           //TODO need WS calls to store this token in the user table

            System.Diagnostics.Debug.WriteLine(newToken);

            connectFCM();
        });
    }

1 个答案:

答案 0 :(得分:0)

从firebase控制台下载GoogleService-Info.plist时,提供的配置确实缺少GOOGLE_APP_ID字段。看完这里的例子后

https://github.com/HabibAli/FCM-Xamarin-Forms/blob/master/FCM/FCM/FCM.iOS/GoogleService-Info.plist

我添加了缺少的属性,Firebase.Core.App.Configure()调用正常。