Skip to content

Commit

Permalink
feat(templates): enable InAppUpdate for Boilerplate's Android version #…
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi authored Mar 17, 2024
1 parent a56e9ed commit cac1f5e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.10" />
<PackageReference Include="Microsoft.Maui.Essentials" Version="8.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="8.0.10" />
<PackageReference Include="Oscore.Maui.Android.InAppUpdates" Version="1.1.0" />
<PackageReference Include="Oscore.Maui.AppStoreInfo" Version="1.0.4" />
<PackageReference Include="Plugin.StoreReview" Version="6.0.0" />
<PackageReference Include="Oscore.Maui.InAppReviews" Version="1.0.0" />
</ItemGroup>

<!-- Build Properties must be defined within these property groups to ensure successful publishing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//-:cnd:noEmit
using Maui.AppStores;
using Maui.InAppReviews;

namespace Boilerplate.Client.Maui;

Expand Down Expand Up @@ -32,7 +33,7 @@ await Dispatcher.DispatchAsync(async () =>
if ((await storageService.GetItem("StoreReviewRequested")) is not "true")
{
await storageService.SetItem("StoreReviewRequested", "true");
await Plugin.StoreReview.CrossStoreReview.Current.RequestReview(testMode: BuildConfiguration.IsDebug());
ReviewStatus status = await InAppReview.Current.RequestAsync();
}
});
});
Expand Down Expand Up @@ -142,21 +143,28 @@ protected override async void OnAppearing()

private async Task CheckForUpdates()
{
if (OperatingSystem.IsAndroid()) // We're using in app updates for android thanks to Oscore.Maui.Android.InAppUpdates
return;

await Task.Delay(TimeSpan.FromSeconds(3)); // No rush to check for updates.

if (await AppStoreInfo.Current.IsUsingLatestVersionAsync() is false)
try
{
if (await storageService.GetItem($"{AppInfo.Version}_UpdateFromVersionIsRequested") is not "true")
if (await AppStoreInfo.Current.IsUsingLatestVersionAsync() is false)
{
await storageService.SetItem($"{AppInfo.Version}_UpdateFromVersionIsRequested", "true");

// It's an opportune moment to request an update. (:
// https://github.com/oscoreio/Maui.AppStoreInfo
if (await DisplayAlert(AppStrings.NewVersionIsAvailable, AppStrings.UpdateToNewVersion, AppStrings.Yes, AppStrings.No) is true)
if (await storageService.GetItem($"{AppInfo.Version}_UpdateFromVersionIsRequested") is not "true")
{
await AppStoreInfo.Current.OpenApplicationInStoreAsync();
await storageService.SetItem($"{AppInfo.Version}_UpdateFromVersionIsRequested", "true");

// It's an opportune moment to request an update. (:
// https://github.com/oscoreio/Maui.AppStoreInfo
if (await DisplayAlert(AppStrings.NewVersionIsAvailable, AppStrings.UpdateToNewVersion, AppStrings.Yes, AppStrings.No) is true)
{
await AppStoreInfo.Current.OpenApplicationInStoreAsync();
}
}
}
}
catch (FileNotFoundException) { }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//-:cnd:noEmit
using Boilerplate.Client.Core;
using Maui.Android.InAppUpdates;
using Maui.AppStores;
using Maui.InAppReviews;
using Microsoft.Maui.LifecycleEvents;

namespace Boilerplate.Client.Maui;
Expand All @@ -15,6 +17,8 @@ public static MauiApp CreateMauiApp()

builder
.UseMauiApp<App>()
.UseAndroidInAppUpdates()
.UseInAppReviews()
.UseAppStoreInfo()
.Configuration.AddClientConfigurations();

Expand Down

0 comments on commit cac1f5e

Please sign in to comment.