Background Tasks in iOS

integerinteger ✭✭PTMember ✭✭

Hello Xamarin.iOS community,

I have a problem in Xamarin iOS, which I still not found a solution, and I need help in order to solve.

I´m trying to create an application that do a task every X minutes, and on that there is not a problems. I created a task and setted it to happen from X minutes in X minutes.

The problem is when after some hours the iPhone OS shutdown my application, for any reason. I already try to catch the override methods in order to understand, a more specific reason why it shutdown, but on my log files, it doesn’t enter on those function, being immediately killed by the OS.

I implemented the “Background Fetch” (adding the option in the Background Modes), with an interval to check for the application, and in spite of that the SO continuous to kill the application.

Anyone have any suggestions, which can help in order to solve this situation?

Thanks in advance.

Answers

  • TedRogersTedRogers ✭✭✭✭ USMember ✭✭✭✭

    @integer background fetch should work but it is not very consistent regarding when you will get the fetch call. You certainly can't use it to do something on a defined interval...at least I never found a way. I don't actually know of a way to get your app woken up at a defined interval. You have to look at the set of background modes and see if any fit your situation. Remote notifications may be your best bet but of course you have to have the background infrastructure to support it.

    Here is an article with some links: https://stackoverflow.com/questions/26933860/launch-wake-ios-app-periodically

  • integerinteger ✭✭ PTMember ✭✭

    Hello, thanks for the sugestion. I tried using the Background Fetch, and in some cases it calls "PerformFetch(UIApplication application, Action completionHandler)" function, where I have my code to verify if the app still running, or if I want to restart, anything that can have stopped.
    But it only goes to that function once, after it enters the first time, it never goes there again, until i reopen the application and put it on background again.

    What does not help me a lot, cause I still have to reopen the application, in order to call the "PerformFetch" and run my code again.

    There is another way to implement the Background Fetch to work like "Android Services", that can be called from time to time? Or another kind of implementation in iOS that allows me to run my code from time to time repeatly?

    Thanks in advance.

  • TedRogersTedRogers ✭✭✭✭ USMember ✭✭✭✭

    @integer I have definitely seen PerformFetch called multiple times but as I mentioned it is not consistent or predictable. I don't know of anything similar to an Android service. As I mentioned, remote notifications may be your best bet.

  • zlazozlazo ✭✭ PEMember ✭✭

    I know this is old but what about start a finite length task in background, when you receive a location update, I already use location for my application and this mechanism works but what I worry about is if the store is going to reject my app because of this

  • MichelMattheyMichelMatthey ✭✭ AUMember ✭✭

    The location Service works fine but Apple will definitely reject it as part of the App Review Process, what a pain!

    I need to run code in the background just like we do on Android using services and restart at device startup but that doesn't exists on iOS, and even using silent remote notifications (Push technology) has it's drawbacks on iOS...

    Running the background code as a background fetch code works fine up to 3 minutes but when it gets killed, only restarting the app will restart the background fetch ?

    Any idea anyone, we have run out of options ?

Sign In or Register to comment.