I am having the following problem in
my statement in iOS. I need to activate a command at the moment the user returns to the application when it is in the background. On my ContentPage
I can not find a method to identify the return. In Android, it works correctly, only in iOS, I can not find any function in the content that shows me that I am returning
protected override void OnAppearing()
{
Debug.WriteLine("OnAppearing()");
base.OnAppearing();
}
protected override void OnDisappearing()
{
Debug.WriteLine("OnDisappearing");
base.OnDisappearing();
}
protected override void OnBindingContextChanged()
{
Debug.WriteLine("OnBindingContextChanged");
base.OnBindingContextChanged();
}
I tried the three options but no results
I usually do it this way so i don't have to bother with subscriptions:
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new MainPage();
}
protected override async void OnStart()
{
if (Application.Current.MainPage is IAppStateAware appStateAwarePage)
await appStateAwarePage.OnStartApplicationAsync();
if (Application.Current.MainPage.BindingContext is IAppStateAware appStateAwareVm)
await appStateAwareVm.OnStartApplicationAsync();
// Handle when your app starts
}
protected override async void OnSleep()
{
if (Application.Current.MainPage is IAppStateAware appStateAwarePage)
await appStateAwarePage.OnSleepApplicationAsync();
if (Application.Current.MainPage.BindingContext is IAppStateAware appStateAwareVm)
await appStateAwareVm.OnSleepApplicationAsync();
// Handle when your app sleeps
}
protected override async void OnResume()
{
if (Application.Current.MainPage is IAppStateAware appStateAwarePage)
await appStateAwarePage.OnResumeApplicationAsync();
if (Application.Current.MainPage.BindingContext is IAppStateAware appStateAwareVm)
await appStateAwareVm.OnResumeApplicationAsync();
// Handle when your app resumes
}
}
public class YourContentPage : Page, IAppStateAware
{
public Task OnResumeApplicationAsync()
{
throw new System.NotImplementedException();
}
public Task OnSleepApplicationAsync()
{
throw new System.NotImplementedException();
}
public Task OnStartApplicationAsync()
{
throw new System.NotImplementedException();
}
}
public interface IAppStateAware
{
Task OnResumeApplicationAsync();
Task OnSleepApplicationAsync();
Task OnStartApplicationAsync();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With