I want to upload the location in background every 30secs to 1min. Is it possible?
I have found that I can set UIApplicationBackgroundFetchIntervalMinimum
. But I looked around this constant to tell the device to fetch about every 30mins. Any way to do that? Thanks.
2 Answers
I don't know the exact purpose of yours for uploading location for every 30 secs. It's not recommended to do so. I think you can go for MonitoringSignificationChanges in CoreLocation framework. It will give you update whenever there is a significant change in location. It helps in saving the battery.
Starts the generation of updates based on significant location changes by the following method:
func startMonitoringSignificantLocationChanges()
This method initiates the delivery of location events asynchronously, returning shortly after you call it. Location events are delivered to your delegate’s locationManager(_:didUpdateLocations:)
method. The first event to be delivered is usually the most recently cached location event (if any) but may be a newer event in some circumstances. Obtaining a current location fix may take several additional seconds, so be sure to check the time stamps on the location events in your delegate method.
Fore more info: Apple Docs

- 4,124
- 2
- 22
- 45
-
I tried already. If the user doesn't move, this delegate method won't be called. I even tried using silent notifications to tell the app to update. After sending for a while, APNs server will stopping sending for about 20mins. And I also tried timer. – Carl Hung Jul 17 '17 at 14:31
-
@CarlHung you should *not* even do it, https://stackoverflow.com/questions/41021733/is-using-core-location-for-performing-functionality-in-the-background-appropriat – Ahmad F Jul 17 '17 at 14:33
-
Sending silent push notifications too many times won't guarantee of delivery through APNS. If too many requests it simply ignore – Sivajee Battina Jul 17 '17 at 14:41
Your approach has multiple problems. Most apps are not allowed to run continuously in the background like you want to do. You get ~3 minutes of background time, and then your app gets suspended. Navigation apps are an exception. If your app is a navigation app you are allowed to run continuously in the background.
Polling the GPS every 30 seconds is also a bad idea unless you're a navigation app. You'll quickly drain the user's battery.
Likewise uploading the user's location every 30 seconds will keep the cellular/WiFi radio on the phone powered up nearly constantly, which will drain the user's battery quite rapidly.

- 128,072
- 22
- 173
- 272