简体   繁体   中英

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

I using Google.Apis.FirebaseManagement.v1 and get config - object IosAppConfig which contains a private key Base64String encoding.

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);
    }

How do I use this data to initialize the 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);
    }

This not work:

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;
    }

Exception

Foundation.MonoTouchException Objective-C exception thrown. Name: com.firebase.core Reason: [FIRApp configure]; ( FirebaseApp.configure() in Swift) could not find a valid GoogleService-Info.plist in your project. Please download one from 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);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM