Initialize MvvmCross in background fetch on iOS
Asked Answered
H

0

6

I'm working on an app that gets Remote Background Fetch (aka. Silent Notification).

What I do, is resolving services with Mvx.Resolve that does the fetching over the network. It's working fine when the app have been launched and put into the background - But since it's not a guaranty that it stays there (low memory or people force closing all backgrounded apps), and MvvmCross therefore is not initialized anymore, I need to initialize it when the app gets woken up.

But I can't seem to just run Setup() and setup.Initialize() at that time, since the Setup constructor requires a UIWindow (witch will be null, when launched in the background) and parsing null, will throw an exception.

I'm aware that Android have a singleton class, that can ensure that MvvmCross is available, like this:

var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(this);
setupSingleton.EnsureInitialized();

but I can't seem to find anything like this, on the iOS platform. The Setup class have a method EnsureInitialized(), but that still requires me to go though the Setup constructor, that requires a UIWindow, as mentioned before.

Can anyone tell me way to do this? One solution is to just manually initialize the services needed. But that seem like a bad solution, since some services may require other services to be loaded though MvvmCross Ioc.

Thanks

Halfway answered 18/1, 2016 at 9:13 Comment(4)
Can't you just save the instance of MvxSetup in your AppDelegate? Isn't that accessible in a Background Fetch?Counterattack
In the case of low memory, or the user force quits the app, the app gets suspended, and all states in the app is gone. When the app gets woken up in the background, by the OS, it will be launched like normal, except it won't get a UIWindow, and therefore it's not possible to initialize MvvmCross with the Setup class (because it depends on a UIWindow to be constructed).Halfway
Can I get you to create an issue on GitHub?Counterattack
For the record, and future people who would be looking for this: github.com/MvvmCross/MvvmCross/issues/1219Halfway

© 2022 - 2024 — McMap. All rights reserved.