-
Notifications
You must be signed in to change notification settings - Fork 2
iOS Start/Sleep/Resume not being called #41
Comments
I get the same situation when running UWP on a WP emulator. Droid is the only one that is actually working fine. I've also asked this question on SO: |
https://github.com/MvvmCross/MvvmCross-Forms/blob/master/MvvmCross.Forms.Presenter.Core/MvxFormsApp.cs#L14 do they get called in a normal Forms app? |
Brand new solution on VS does the expected:
Console output for iOS run:
and Console output for Droid run:
I switched the app a few times to BG and back. |
Are you sure that your |
As it goes as a parameter to the presenter and it saves it, I did not think it was necessary.
Anyway, I created a local fiend but unfortunately, got the same end result. |
So I got the source code for the presenter, and added the Example002XAML PCL/iOS into it, removed packages from it and pointed to src code on the solution. Unfortunately, only the ctor one is hit, the overrides never came. But as I already tested a pure Form app and they are calling this, looks like we are doing something out of order? Any other idea that can help me move further in the investigation? |
Something else I just found, there is no |
Probably exactly what is missing?
Above code is from a pure Xamarin Forms iOS project. Looks like we need some refator on the base class here? |
Is there any update on this one? Is there a workaround? This probably also causes the Start/ReloadState/SaveState to be not called on iOS. |
I solved this in my current project by doing the following:
Basicly the solution consists in using LoadApplication and removing the explicit window. |
Thanks! How does your Setup and FormsApp class look like? Do I need to initialize the MainPage in the FormsApp class? What did you pass to the MvxIosSetup base class constructor? |
My setup looks like this:
MyFormsApp (inside the PCL) is just:
My custom presenter is something like (the window reference is not needed):
|
Thanks! Do the application lifecycle events work correctly for you? On android, the OnResume method on the FormsApplication does not get called, when bringing the app to foreground, but the OnStart method is called instead. On iOS the OnResume method on the FormsApplication works, but the OnStart method is not invoked on the ViewModel on resume. The SaveStateToBundle and ReloadFromBundle methods on my view model are never executed, neither on android nor iOS. |
These application lifecyle methos have nothing to do with the view models direclty (or at least out of the box). They work fine for my app. The Start method of the MvxViewModel is called after the view model is instantiated by the ViewPresenter. I had to forward these events to my view model manually. For example, for 'App -> OnResume' I get the topmost view (Page), then I get the binding context and if the binding context is my BaseViewModel then I call OnResume on it. I can't tell you more about SaveStateToBundle and ReloadFromBundle because I'm not using them in my forms app but I guess they also need to be triggered. Moreover, I defined methods like OnSuspended, OnResumed, OnLoaded etc in my BaseViewModel and trigger them from a BasePage by overriding Page methods like OnAppearing, OnDissapearing, OnBindingContextChanged, OnBackButtonPressed. This way my ViewModels are aware of the state of their views. |
Hey there,
I've code like this on MvxIosSetup:
But those methods are never called.
Is this a known issue or am I doing something wrong?
The text was updated successfully, but these errors were encountered: