Stop Updating Locations on ios when user clicks stop button - ios

I am using location services in my ios app for tracking purposes. The app tracks location in foreground as well as background, until the app terminates.
Here all the code is written in react-native java script except the beacon tracking API values which are being sent from native ios code through app delegate and location manager.
The app updates locations in all cases throughout the life cycle of app but sends beacon values to API only after a specific track interval. There is a stop button, on clicking of which the app stops sending location values to API but the location manager still continues to change lat long values.
What i want is, the clicking of stop button should stop the location manager updates and should start only when i click on 'start' button. This can be handled through app delegate methods but they are called only when any app transition happens like switching from foreground to background or vice versa.
They are not called if i switch between screens remaining on foreground only. And all the screens are handled through react code only, not in native ios.
Suggest something to control the location manager activities in the manner mentioned above, please.

Related

Detect when app killed by user in background state iOS

I am working in a chat application where I need to show user status (offline/online).
When my app is in foreground and background then I need to show user as online (managing by VoIP).
But when the user kill the app then it should go to offline.
I have to maintain a flag to show offline which I am managing in delegate function applicationWillTerminate but this function only called when app is in foreground state and user kill it by pressing double tap home button and swipe up.
This function does not get called when app is in background state. I mean simply press home by single tap (app will go in background) then again double tap to swipe up.
Is there any function where I get 100% call either app is in background/foreground state and user kill the app?
Is there any function where I get 100% call either app is in background/foreground state and user kill the app?
No. Just the opposite. If your app is terminated when already in the background, if it is suspended (ie not running in the background due to special entitlement), it is 100% certain you will get no event. You cannot. You are suspended and not running. The app dies in its sleep.
No, As per Apple Document
https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623111-applicationwillterminate?language=objc
For apps that support background execution, this method is generally not called when the user quits the app because the app simply moves to the background in that case.
What you can do execute a method(which hit an API for keeping status online) after few seconds(whatever you find suitable time) when you app goes in Background, If method is calling successfully after that specific seconds then user stay online, if its not call after specified second then server update its status to offline. So It require both server and client handling.

Will geofencing events be called if the app is terminated in iOS 11?

I'm trying to call didEnterRegion and didExitRegion for geofencing events when the app is killed (double tap home and swipe up by the user), but I'm not sure if this is even possible. From what I've seen, such as here, it isn't possible. However, I was wondering if something had changed in iOS 11, or if there was another way to do this?
After running many tests, I can confirm that Geofence Events are called, even when the app is terminated (swipe up). However, the user must have authorized location to be used when the app isn't running, and other background location functions, such as didUpdateLocation will not be called.

how to run code logic in the background in swift

I am new to swift. Here is the following thing I am trying.
Track the location and motion status of the user in the background. When user's motion status goes from walking to running I want to track the location. And when the app comes to foreground I want to pin the tracked location where the user started running from walking.
It works fine when the app is in foreground entire time. But it does not work when the app is in background.
How shall I implement the code for the logic to be executed in the background?
Location service in the background:

How to tell when user interacts with iOS location-aware lock screen app icon

My app uses location services in the background and as a result it shows on the iOS 8 lock screen (see picture). Is there any way to tell when an app is brought to the foreground by the user sliding this button?
The app will necessarily be launched when this button appears -- since it's being awakened by the same location signal that is causing it to appear on the lock screen. Accordingly, application:didFinishLaunchingWithOptions: has a launch options dict with UIApplicationLaunchOptionsLocationKey = 1.
That's useful, but what I want to know is when the app is brought to the foreground due to interaction with the button. No relevant application delegate methods seem to be called in this case, except didBecomeActive: and didMoveToForeground: but these methods don't carry extra data.

CLLocationManager don't stop

Dear fellow developers,
I am trying hard to find a solution for my problem regarfing CLLocationManager.
I use a CLLocationManager instance in my Application. If the user selects the Home button on the device or terminates the application I want the location services to stop.
Therefor I call [self.locationManager stopUpdatingLocation]; - But this somehow doesn't work. The application enters the background and the small location arrow in the upper right corner of the status bar don't disappear. Even if I add [self.locationManager release] or self.locationManager.delegate = nil; - the location tracking don't stop :-/
It only disappears if I go to my device settings and switch off location services for the app. Whenever I switch back to location service enabled I immediately get a purple colored arrow next to the switch toggle and the icon reappears in the status bar.
My question is how can I turn off location services when the app enters the background or is terminated?
Thanks a lot in advance and have a nice day :-)
Your location is disabled. The location service icon "meaning" has changed on iOS 5. Take a look at this question: https://apple.stackexchange.com/questions/27463/why-is-the-location-services-icon-always-present
I Quote the answer:
It's a new feature in ios 5 called "region Monitoring"
The reason it's active even if the app is closed is that this feature
runs in iOS 5 core and notifies all apps that are registered when they
have entered or left a specific geo-fence.
Reminders does that when you use a location based reminder.
Although the location icon appears at all time. This actually has very
minimal impact on the battery due to apple really optimizing this
feature by using cell and wifi mostly.
Your app is working ok. The system behaviour is the one who changed.
You do it the right way. When entering background, it's ok if some delegate methods are called for some seconds. That should stop.
Where do you stop the location updates ? Are you sure it is triggered ? If yes, are your delegate method called even if the visual indicators tell something else ?
Are you sure you don't trigger a method that reactivate the location update after you have stopped it (because for example you can receive some updates even after stopped).
For instance if you started monitoring a significant location change, then you should unsubscribe from it with the corresponding pair method. If you are using region enter, then until you unsubscribe, the system will notify your delegates.

Resources