TobiasBuchholz / Plugin.Firebase

Wrapper around the native Android and iOS Firebase Xamarin SDKs
MIT License
220 stars 49 forks source link

Crash when use different plist file #327

Open MattePozzy opened 3 months ago

MattePozzy commented 3 months ago

Hi, I have the same app code that produce two different apps with different bundle id. I have created tow plist file and put inside the folder Platform iOS.

I load the plist file based on the app package name, but when I try to pass the plist path at the CrossFirebase.Initialize function the app crashes with this error:

System.Exception: 'Could not initialize an instance of the type 'Firebase.Core.Options': the native 'initWithContentsOfFile:' method returned nil.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.'

this is the code used to load the plist file:

events.AddiOS(iOS => iOS.WillFinishLaunching((_, __) =>
{
    string plistName = "", plistPath = @"\Platforms\iOS\";
    switch (AppInfo.PackageName)
    {
        case "bundle.id.one":
            plistName = "ONE_GoogleService-Info.plist";
            break;
        case "bundle.id.two":
            plistName = "TWO_GoogleService-Info.plist";
            break;
    }

    plistPath = @$"{plistPath}{plistName}";

    Firebase.Core.Options opt = new(plistPath);
    CrossFirebase.Initialize("myName", opt);
    CrossFirebaseCrashlytics.Current.SetCrashlyticsCollectionEnabled(true);
    return false;
}));

inside the csproj file:

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-ios'">
    <BundleResource Include="Platforms\iOS\PST_GoogleService-Info.plist" Link="PST_GoogleService-Info.plist" />
    <BundleResource Include="Platforms\iOS\SGAT_GoogleService-Info.plist" Link="SGAT_GoogleService-Info.plist" />
</ItemGroup>