FirebasePushNotificationManager.Initialize iOS 不使用 GoogleService-Info.plist

FirebasePushNotificationManager.Initialize for iOS without using GoogleService-Info.plist

我使用 Google.Apis.FirebaseManagement.v1 并获取配置 - 包含私钥 Base64String 编码的对象 IosAppConfig。

public static Dictionary<string, string> ConvertToDictionary(string base64String)
    {
        byte[] bytes = Convert.FromBase64String(base64String);
        string json = Encoding.UTF8.GetString(bytes);
        return JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
    }

如何使用此数据初始化 FirebasePushNotificationManager

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
   
        global::Xamarin.Forms.Forms.Init();
        LoadApplication(new App());
        FirebasePushNotificationManager.Initialize(options, true);
        
      
        return base.FinishedLaunching(app, options);
    }

这不起作用:

FirebasePushNotificationManager.Initialize(WriteDataConfig(
             CLIENT_ID,
            REVERSED_CLIENT_ID,
            API_KEY,
            GCM_SENDER_ID,
            PLIST_VERSION,
            BUNDLE_ID,
            PROJECT_ID,
            STORAGE_BUCKET,
            GOOGLE_APP_ID
            ), true);
  .....

 private NSDictionary WriteDataConfig(params string[] config)
    {
        var dictionary = new NSDictionary(
            new NSString("CLIENT_ID"), new NSString(config[0]),
            new NSString("REVERSED_CLIENT_ID"), new NSString(config[1]),
            new NSString("API_KEY"), new NSString(config[2]),
            new NSString("GCM_SENDER_ID"), new NSString(config[3]),
            new NSString("PLIST_VERSION"), new NSString(config[4]),
            new NSString("BUNDLE_ID"), new NSString(config[5]),
            new NSString("PROJECT_ID"), new NSString(config[6]),
            new NSString("STORAGE_BUCKET"), new NSString(config[7]),
            new NSString("IS_ADS_ENABLED"), false,
            new NSString("IS_ANALYTICS_ENABLED"), false,
            new NSString("IS_APPINVITE_ENABLED"), true,
            new NSString("IS_GCM_ENABLED"), true,
            new NSString("IS_SIGNIN_ENABLED"), true,
            new NSString("GOOGLE_APP_ID"), new NSString(config[8])
        );
        return dictionary;
    }

异常

Foundation.MonoTouchException Objective-C 抛出异常。名称:com.firebase.core 原因:[FIRApp configure];(Swift 中的FirebaseApp.configure())无法在您的项目中找到有效的 GoogleService-Info.plist。请从 https://console.firebase.google.com/.

下载一个
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        
        global::Xamarin.Forms.Forms.Init();
        LoadApplication(new App());
      
        var optionsFirebase = new Firebase.Core.Options(GOOGLE_APP_ID, GCM_SENDER_ID)
        {
            ClientId = CLIENT_ID,
            ApiKey = API_KEY,
            StorageBucket = STORAGE_BUCKET,
            ProjectId = PROJECT_ID,
            BundleId = BUNDLE_ID,
        };
        Firebase.Core.App.Configure(optionsFirebase);
        FirebasePushNotificationManager.Initialize(options);
       
        return base.FinishedLaunching(app, options);
    }

我的样本:FirebaseTestNotification