How do I prevent a Xamarin IOS app from constantly restarting.

PaulDivanPaulDivan USMember ✭✭

I have a Xamarin IOS app that I created for a customer that tracks their field agents movements and also manages their workflow. I use CLLocationManager to track the phone's current location and I use CMMotionActivityManager to monitor the user's activity so I can determine if they are driving or walking/running which allows me to check to see if they have arrived at a delivery point or their home. All users have location tracking to "Always Allow". Activity tracking is also set to always track. All the phones are 10 XR phones and are on the latest version of IOS. The app communicates with a web services layer for all data it needs for managing the user's job list. It also uses the services layer to send geolocation information. It also has a service for sending log entries. All outgoing communication is saved in a SQLite database and are only marked sent when the associated service confirms it has received the data.

It's extremely difficult to determine what the cause of the restarts are. I am monitoring memory usage, I have the code tightly wrapped to trap exceptions and exceptions are logged. Right now the only exceptions I see are when there is a network timeout which are expected since the agents are often times in areas with little or no network coverage.

Has anyone seen this type of behavior? I am seeing the app come up and then restart, run for a couple of minutes and they restart again, then run for hours and even days and restart again. You can see it in the Fast App Switcher and the page image looks correct but when you select it the app restarts.

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    I don't know what the restarting here means. If you are saying the application will be temporarily waken up at sometime when it doesn't work on any other tasks.
    It may happen due to the location service with the background mode. As you said above, all the devices have enabled the Always Allow setting and if you have also enabled the background mode for the location updates:
    https://developer.apple.com/documentation/corelocation/getting_the_user_s_location/handling_location_events_in_the_background?language=objc
    The app will be relaunched even though at the suspended state.
    But if your project has been completely terminated it won't be restarted automatically.

  • PaulDivanPaulDivan USMember ✭✭

    Thank you for the quick response. I'm looking at the link you sent and it looks like there are a few things for me to look at.

    So, by restarting this is what I see: The app appears in "Fast App Switcher" showing the same page as I left it on. But, when I select it to bring it back into the foreground the app goes through the standard startup sequence where I see it entering the FinishedLaunching method in AppDelegate. And during the time prior to this, once it's in this state no background geolocation messages or activity messages are received.

    I am also subscribing to the PerformFetch events and I see them come in but when the app goes back through its FinishedLaunching sequence again there is a 10-15 minute interval between the last PerformFetch and the FinishedLaunching calls.

  • LandLuLandLu Member, Xamarin Team Xamurai

    I didn't use "Fast App Switcher" before. If your app has come into the suspended state it will relaunch when you select the icon to open it.
    PerformFetch is the same as the background location service. They are all controlled by the system. The system will determine the appropriate time to wake up your application to run some tasks.
    They all could cause the "restarting" of your application.

Sign In or Register to comment.