I am working on CLLocationManager. My App is register for Background "App registers for location updates". But When I am calling "stopUpdatingLocation" and went to background my app is not running more (My app become in Inactive state).
Why LocationManager behaves like that? Even my app is register for background location updates.
You have to Read and Check this link.
You have to Some changes in app.plist file like:
1) If your app use on location services to function properly, You have to add location-services to UIRequiredDeviceCapabilities.
2)if your app requires GPS service, you have to add GPS to UIRequiredDeviceCapabilities.
3) if you need to run your app longer then 10 minutes in the background, add location to UIBackgroundModes. Then your location manager will deliver locations beyond the 10-minute-limit.
4)you should also set NSLocationUsageDescription (can also be localized)
Have you used locationManager:didFailWithError: method? The possible reasons were enumerated.
Related
I am trying to listen for iBeacons when my app is not running (the user quit the app and it is not running in the background).
I have specified the Bluetooth LE Background Mode and can listen for and receive sightings when the app is active and in the background. However, I am having a difficult time figuring out how to implement the same functionality for when my app is not running.
I've been reading the Core Bluetooth guide and trying to implement CBCentralManagerDelegate - if that is the correct solution for this scenario. I don't understand where I implement the CBCentralManagerDelegate. Do I implement it in the AppDelegate or in the view controller that handles beacon sightings? Do I have to declare a CBCentralManager? What do I do in centralManagerDidUpdateState:?
I don't care about restoring or preserving state, I just want my application to receive beacon sightings when it is not running.
I have added the NSLocationAlwaysUsageDescription and am asking for permission for the location.
Let me know if I can provide more information.
Apple treats iBeacon support differently than other BLE services.
It considers iBeacons monitoring to be a Location Manager service.
You want to add the NSLocationAlwaysUsageDescription key to your app's info.plist.
At startup, you want to check the location manager's authorization status, and if it's not kCLAuthorizationStatusAuthorizedAlways then you want to request it. That code looks like this:
CLAuthorizationStatus status =[CLLocationManager authorizationStatus];
if (status != kCLAuthorizationStatusAuthorizedAlways
&& [self.theLocManager respondsToSelector:
#selector(requestAlwaysAuthorization)])
{
[self.theLocManager requestAlwaysAuthorization];
}
EDIT:
In your app delegate's application:didFinishLaunchingWithOptions: method, you need to check the options for the key UIApplicationLaunchOptionsLocationKey.
To quote the relevant part of the CLLocationManager Class Reference:
If a region boundary crossing occurs while your iOS app is not
running, the system automatically wakes it up (or relaunches it) in
the background so that it can process the event. In this case, the
options dictionary passed to the
application:didFinishLaunchingWithOptions: method of your app delegate
contains the key UIApplicationLaunchOptionsLocationKey to indicate
that your app was launched because of a location-related event. During
the relaunch process, you must recreate your location manager object
and assign a delegate capable of handling region-related events. After
you do that, the system delivers the region notification for which
your app was launched. All of the regions you configured previously
are made available in the monitoredRegions property of any location
manager objects you create.
I am implementing an App with continuous background updates on iOS 9. Even with allowsBackgroundUpdates set to YES, AlwaysUsage Description and with proper authorisation i am not getting location updates continuously. I am using Standard Location Services and Significant Location Services but not receiving any location updates when App is in Background. (App is in background/suspended but not terminated). Can anyone let me know if i have missed anything? Thanks in advance.
If your iOS app must keep monitoring location even while it’s in the background, use the standard location service and specify the location value of the UIBackgroundModes key to continue running in the background and receiving location updates. (In this situation, you should also make sure the location manager’s pausesLocationUpdatesAutomatically property is set to YES to help conserve power.) Examples of apps that might need this type of location updating are fitness or turn-by-turn navigation apps
I am creating an application that sends updated location to server regardless of app state. I have tried silent push to wake my application in background but it didnt work (it works fine except if my app is killed by user from app switcher). I am using location manager for getting current location.
Does IOS7 provides this feature to launch your application in background (even if app is killed by user from app switcher)??
I have spent five days without any success on this. If anyone can help me that would be highly appreciable.
Thanks in advance!!
If you need precise GPS locations you can set add the "location" value to the UIBackgroundModes array in your Info.plist as described in "UIBackgroundModes location and significant location changes with region monitoring". If you need only approximate locations you can use the startMonitoringSignificantLocationChanges method of CLLocationManager. As it is written in the documentation: "If you start this service and your application is subsequently terminated, the system automatically relaunches the application into the background if a new event arrives."
You can wake your app by using significantlocationchange.
You have to start significant location change while you switch your app to background.
Then system will wake your app after significant location change.
The frequency is not faster than 5 min and for every 500 meters.
You will have to catch the event by checking for LocationKey in didFinishLaunchingWithOptions in projects AppDelegate.
Ok, so I currently have an app where I register a geofence to be monitored using the CLLocationManager startMonitoringForRegion method. This works fine when the app is in the foreground and background.
I also have the appropriate plist values set:
UIBackgroundModes :{location}
UIRequiredDeviceCapabilities: {location-services}
What doesn't work
After a device restart, the app is not being relaunched. I can force this to happen if I set startMonitoringSignificantLocationChanges before entering background. But this method uses much more battery life and I don't need the location all the time, just whenever I break a geofence.
The docs for regions say:
In iOS, the regions you register with the location manager persist between launches of your application. If a region crossing occurs while your iOS app is not running, the system automatically wakes it up (or relaunches it) in the background so that it can process the event. When relaunched, all of the regions you configured previously are made available in the monitoredRegions property of any location manager objects you create.
Question
Is it possible (when using geofencing regions) to have the system restart my app AFTER a system reboot, WITHOUT using startMonitoringSignificantLocationChanges ?
Edit: I am targeting iOS6 & iOS7
Answering my own question here.
While you do need to use the startMonitoringSignificantLocationChanges to get the system to wake up the app after a device reboot. Nothing will wake up the app if the user has force closed it.
For my purposes, I did not need to set UIBackgroundModes to location. This setting is usually used for applications that only need fine-grained location updates (E.g. using startUpdatingLocation). Setting the background mode is not required when using startMonitoringSignificantLocationChanges.
I just wanted to know what happens, when i select app registers for location updates under "Required background modes" in Xcode for an IOS app.
VOIP provides aliveTimeOutHandler for specific duration. In same way, whether location services provides any aliveTimeOutHandler method? I am using IOS7
When your app registers for location updates it will periodically check for location changes when in the background. Of course this is just a switch in project settings that enables that bground mode for your app. You need to actually implement the background task (write some code). You can see the accepted answer here on how to achieve this.