Issue tracking location on Apple Watch - cllocationmanager

I have built an Apple Watch App which uses CLLocation to track the users location. The idea of the app is for it to work using the built in GPS and not need the phone.
When I run the watch app it prompts me to give the various permissions which have to be granted from the phone app.
If I do this and then start tracking on the watch I get an initial call to
- (void)locationManager:(CLLocationManager*)manager didFailWithError:(NSError*)error
which is quite normal, I just start tracking again. I then get a handful of calls to
- (void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray*)locations
But then it just stops receiving updates.
If I run a full track on the iPhone and then run the track on the Watch the tracking works fine.
Tests done:
checked permissions for both workout and location are set correctly on the iPhone
if on the track that is not receiving updates you deny permission to location services on the phone and then turn it back on again it again calls the two methods above a handful of times and then stops. So everything is staying in memory
tested on a running app, 'Pear', and seemed to get the same bug, that is it doesn't track location on the watch on the first run.
I think it's most likely an Apple bug, but I'm hoping someone here can somehow point me in a direction that I may have missed.

Related

Can we get user current location when app is not running in iOS?

We would like to track user so we want user current location when app is not running also.
We are tracking user when app is in background or foreground mode but in some cases like battery drain, memory footprint issue etc, app going to auto kill so in that case we can not track user. We have used startMonitoringSignificantLocationChanges also but in this case we are getting user location once user moved around 500 meter or more from their current location. If user not move after app kill, we can not track. Is there any way to do this?
Certain types of apps, like turn-by-turn navigation apps, are allowed to run from the background, and can continue to monitor the user's location.
Normal apps cannot. If the system terminates your app you stop receiving location updates. As you say, you can use startMonitoringSignificantLocationChanges or geofencing to get updates when the device moves a significant distance, but I don't think there is another solution for an app store app.
("Kill mode" isn't really a meaningful term.)

React Native iOS app restart on reboot

I want to create an iOS app using React Native. One of the primary features of the app is that it runs constantly in the background. It also requires using GPS btw (in case that is important).
I have had a number of devs tell me its not possible to do this for iOS, however I have read that it is do-able.
Is this possible to do in the iOS environment? Mainly, if the app is running when the phone is powered off, can you make it open when the device is restarted without the user opening it?
I should say that I am a RN novice and any help is much appreciated.
If your app gets permission to get location while it's not in the foreground, then you will get periodic updates and some time to process it.
For example, if you are giving driving directions.
https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html#//apple_ref/doc/uid/TP40009497-CH2-SW10
If there is no good user benefit for you to get the location in the background constantly, you might be rejected. Apple suggests region monitoring instead
iOS supports the delivery of location events to apps that are suspended or no longer running. The delivery of location events in the background supports apps whose functionality would be impaired without them, so configure your app to receive background events only when doing so provides a tangible benefit to the user. For example, a turn-by-turn navigation app needs to track the user’s position at all times and notify the user when it’s time to make the next turn. If your app can make do with alternate means, such as region monitoring, it should do so.
I have no idea how RN wraps this behavior, but no matter what it does (or what a plugin might do), the core iOS behavior is how it is described in that URL.
I verified yesterday (at least on iOS 11.2 simulator) that automatically restarting the app (and the location tracking) after phone reboot works.
The key point is that startMonitoringSignificantLocationChanges needs to be on to wake up the app after reboot. For me the difficult part was figuring out when to turn it on, because I couldn't find a reliable way to detect when the phone is being rebooted or run any code at that point. However, based on initial testing it looks like startMonitoringSignificantLocationChanges is independent and doesn't negatively impact the usual location updates, so now I just leave it on all the time and toggle startUpdatingLocation / stopUpdatingLocation on top of it based on Core Motion-detected activity.
Otherwise requirements are the same as for any location tracking on the background, i.e. handle permissions and don't process too much. Apple documentation explains how to detect that the app was relaunched by a location event.
Here's a react native module which basically helps you achieve what you're describing: https://github.com/transistorsoft/react-native-background-geolocation

Initiate location capture at a particular time even if the app is in background or not running

Is there any way in latest iOS to initiate location capture at a particular time each day (say morning and evening ), even if the app is in background or not running.
You should read Background execution. Background jobs are actually not recommended:
An app might move to the background because the user launched a different app or because the user locked the device and is not using it right now. In both situations, the user is signaling that your app does not need to be doing any meaningful work right now. Continuing to run in such conditions will only drain the device’s battery and might lead the user to force quit your app altogether.
As for getting user location check this answer How can I get current location from user in iOS

iOS8 background standard-location updates after termination

I'm wondering if, in iOS8 with all possible background-modes turned on, the app will be woken up after termination to deliver location updates using the standard-location updates monitoring?
I've read all possible documentations, but I find it quite confusing because it at one point says the device will wake up the app, and at another point is says the device will not wake up the app when using standard-location updates.
My app needs continuous location updates with a movement-threshold of about 150 meters (max), and therefore the standard-location-monitoring seems appropriate. It also needs to keep getting these updates even if the app is terminated by the system, as it is crucial to the user.
I've come to understand that if using the significant change location monitoring the app will be woken up upon delivery of new data, but I'm still confused about the standard location monitoring when having requested Always authorization and having the background updates for location turned on.
Have anyone tested this, or know what happens? And if the app is not woken up after being terminated by the system, how can I solve that problem?
Thanks.
Standard location is something your app does. Thus your app needs to be running. It can operate in the foreground or you can even run in the background. But if your app is not running, it's not running; there is nothing to track.
Significant location monitoring and region monitoring, on the other hand, are done for you by the system, so it runs even if your app is not running, and you are woken up or launched to receive updates.

Why location icon remains on even if I killed foursquare from background

I had done loads of R&D on locations services and I come to know that if you kill app from background then there is no way you can get location update.
but now I observed even if I kill Foursqure from background it still uses location services as location icon is present on the top, Once I turn off location services for foursquare location icon gets disappeared from top.
please guide me how foursquare do this?
Apps can register to get deferred location updates. This means that the OS can accumulate location data and feed it to the app later when the program is launched. Perhaps this is what's going on with Foursquare?
From Apple docs:
In iOS 6 and later, you can defer the delivery of location data when
your app is in the background. It is recommended that you use this
feature in situations where your app could process the data later
without any problems. For example, an app that tracks the user’s
location on a hiking trail could defer updates until the user hikes a
certain distance and then process the points all at once. Deferring
updates helps save power by allowing your app to remain asleep for
longer periods of time.

Resources