I have my interface
interface IAppServices {
Task NavigateAsync(string pageName, bool iAnimated, Dictionary<string, object> Object);
Task NavigateAsync(string pageName, bool iAnimated);
Task DisplayAlertAsync(string title, string message, string CancelMessage);
Task DisplayToastAsync(string message, ToastDuration toastDuration, double fontSize);
}
and my implementation
namespace Demy_IA.Services;
class AppServices : IAppServices {
public async Task DisplayAlertAsync(string title, string message, string CancelMessage) {
await Shell.Current.DisplayAlert(title, message, CancelMessage);
}
public async Task DisplayToastAsync(string message, ToastDuration toastDuration, double fontSize) {
var toast = Toast.Make(message, toastDuration, fontSize);
await toast.Show();
}
public async Task NavigateAsync(string pageName, bool iAnimated, Dictionary<string, object> Object) {
await Shell.Current.GoToAsync(pageName, iAnimated, Object);
}
public async Task NavigateAsync(string pageName, bool iAnimated) {
await Shell.Current.GoToAsync(pageName, iAnimated);
}
}
How can I check internet conenectivity in the creation on mauiProgram
public static MauiApp CreateMauiApp() {
// Check internet connectivity before starting the app
var builder = MauiApp.CreateBuilder();
var firebaseAuthConfig = new FirebaseAuthConfig() {
ApiKey = "AIzaSyBm8iocSck29uHfMZ7tI_B5TD3z-9hpvhQ",
AuthDomain = "demy-ia-6ca24.firebaseapp.com",
Providers = new FirebaseAuthProvider[] {
new EmailProvider()
}
};
builder
.UseMauiApp<App>()
.ConfigureSyncfusionCore()
.UseMauiCommunityToolkit()
.ConfigureFonts(fonts => {
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
#if DEBUG
builder.Logging.AddDebug();
#endif
builder.Services.AddSingleton<HttpClient>();
builder.Services.AddSingleton<IAppServices, AppServices>();
builder.Services.AddSingleton<IHttpService, HttpService>();
builder.Services.AddSingleton<AppShell>();
builder.Services.AddTransient<AppShellViewModel>();
builder.Services.AddSingleton<LoginPage>();
builder.Services.AddSingleton(Connectivity.Current);
var firebaseAuthClient = new FirebaseAuthClient(firebaseAuthConfig);
builder.Services.AddSingleton(firebaseAuthClient);
builder.Services.AddSingleton<IAuthenticationService>(serviceProvider => {
var authService = serviceProvider.GetRequiredService<FirebaseAuthClient>();
return new AuthenticationService(authService);
});
return builder.Build();
}
}