Skip to content

Commit

Permalink
✨ Mobile | Install Google Analytics (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharykeeping committed May 31, 2024
1 parent d4919e8 commit 0b734f6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ios-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ jobs:
- name: Update Build Number
run: sed -i '' "s|<ApplicationVersion>.*</ApplicationVersion>|<ApplicationVersion>${{ inputs.build_number }}</ApplicationVersion>|g" src/MobileUI/MobileUI.csproj

- name: Update GoogleService-Info.plist
shell: bash
run: |
echo ${{ vars.GOOGLESERVICE_INFO_PLIST }} | base64 --decode > src/MobileUI/Platforms/iOS/GoogleService-Info.plist
- name: Setup DotNet Environment
uses: actions/setup-dotnet@v3
with:
Expand Down
21 changes: 21 additions & 0 deletions src/MobileUI/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.AppCenter.Analytics;
using Microsoft.AppCenter.Crashes;
using Microsoft.Extensions.Logging;
using Microsoft.Maui.LifecycleEvents;
using Microsoft.Maui.Platform;
using Mopups.Hosting;
using SkiaSharp.Views.Maui.Controls.Hosting;
Expand Down Expand Up @@ -38,6 +39,7 @@ public static MauiApp CreateMauiApp()
.UseSkiaSharp()
.UsePageResolver()
.UseBarcodeReader()
.RegisterFirebase()
.ConfigureMauiHandlers((handlers) =>
{
handlers.AddHandler(typeof(TableView), typeof(CustomTableViewRenderer));
Expand Down Expand Up @@ -88,4 +90,23 @@ public static MauiApp CreateMauiApp()

return builder.Build();
}

private static MauiAppBuilder RegisterFirebase(this MauiAppBuilder builder)
{
builder.ConfigureLifecycleEvents(events =>
{
#if IOS
events.AddiOS(iOS => iOS.FinishedLaunching((app, launchOptions) => {
Firebase.Core.App.Configure();
return false;
}));
#else
events.AddAndroid(android => android.OnCreate((activity, bundle) => {
Firebase.FirebaseApp.InitializeApp(activity);
}));
#endif
});

return builder;
}
}
7 changes: 7 additions & 0 deletions src/MobileUI/MobileUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@
<PackageReference Include="Xamarin.Firebase.Messaging" Version="123.3.1.2" />
<PackageReference Include="Xamarin.GooglePlayServices.Base" Version="118.2.0.6" />
<PackageReference Include="Xamarin.Google.Dagger" Version="2.48.1.2" />
<PackageReference Include="Xamarin.Firebase.Core" Version="121.1.1.8" />
<PackageReference Include="Xamarin.Firebase.Analytics" Version="121.3.0.6" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.Contains('-ios'))">
<BundleResource Include="Platforms/iOS/GoogleService-Info.plist" Link="GoogleService-Info.plist" />
<PackageReference Include="Xamarin.Firebase.iOS.Analytics" Version="8.10.0.3" />
</ItemGroup>

<!--https://github.com/dotnet/maui/issues/16514-->
<PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions src/MobileUI/Platforms/iOS/GoogleService-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Copy from Keeper

0 comments on commit 0b734f6

Please sign in to comment.