Using Location Manager when app is removed from background in iOS 7 - iphone

I am developing one app, i would like to know about location manager that will it work when user remove the app from background in iOS 7 and above?
I am using this delegate method:
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;
Will it get called when the app is removed from background?
The distance filter i have set is 50 meters with desiredAccuracy of NearestHundredMeters.
Regards,
Aamir

if you want to run your app when app is removed from background, you have to follow some instruction which are in this document.
https://developer.apple.com/Library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/RegionMonitoring/RegionMonitoring.html

If you would like a function to run in background simply go to AppDelegate and place your code block in the "applicationDidEnterBackground" function AppDelegate Location

Related

CLLocationManager singleton iphone example

I am new to iPhone development, i am creating a location based app. i have searched lot related to location and came to knew that use one object ( singleton pattern ) of CLLocationManager through out app, in my app i have to update user's location to server using web service,
UPDATE
as discussion with Umer i came to knew that i can use one object in appdelegate of CLLocationManager and implement delegate methods in that, and update user location to server in app delegate ,
So, is it good to do in appDelegate ??
please help.
Your locationservices will run both in foreground and background, but to allow it to run in background (when the app is open and minimized), you need to declare a special background mode in your projects "Plist" file, if I'm not wrong.
The method didUpdateToLocation will give you updates every time there is a significant movement, which you can define and adjust through various settings, such as CLLocationAccuracy (locationManager.desiredAccuracy and locationManager.distanceFilter).
Depending on what desired accuracy you ask, battery main drain quicker or not.
I don't understand what you mean with "web service". These are not web-related, they're native functionalities of iOS.
You can just call the delegate method of locationManager StartUpdatingLocation when user moves to significant distance & also call the web-service for updating User's Location.
Both Task are done in Background mode.
UPDATED ANSWER
SOURCE CODE

Location manager stops working after some interval in background

I m developing an app in which I have to track the LocationUpdate in the Background as well as in the Foreground but after some time interval in the Background the app stops updating the Location. When I take it back to Foreground it starts again and when I put it in background after some time interval it stops again.
I am not able to find the issue please help me if possible.
You have to specify that your app need location updates when in background in plist
Here is apple docs Getting Location Events in the Background
and here is a tutorial for this.
And I would recommend you to read Location Awareness Programming Guide
disable distance filter
set desired Accuracy to best
use - (void)startUpdatingLocation
Now in ios6: there is
locationManager:didUpdateLocations:
in ios5 there is
locationManager:didUpdateToLocation:fromLocation:
the first delivers the locations buffered in the background and keeps your application sleeping and wakes it up with a sequence of fixes, while the ios5 method delivers the location all of the time.

GeoFencing on iOS

I am using GeoFencing to set a region and perform some task when user Enters or Leaves the region. Bt it is not working for me, i am using gollowing code
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(some values,some values);
CLRegion *region = [[CLRegion alloc]initCircularRegionWithCenter:coord radius:15.0 identifier:#"SF"];
[locationManager startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyBest];
But None of the delegates didEnterRegion and didExitRegion being called when i close the application and the app is monitoring and i move away from that region or enter.
You define a radius of 15m. That is too small. First, try with 50m or more. Look at the map app, if you really have entered that region.
Furthermore, I hope you meant "send to background", instead of closing.
make sure you have set your app to be allowed to run in background? (via plist)
Update:
Finally it turned out that you terminated the application. Then of course you will not get any loctaion events anymore.
Solution:
Don't terminate it via double click on home button follwed by selecting the white cross, simply close it with one click on home button, then it has chance to run in background.
Update2:
Even when the app was terminated, ios relaunches it when it has registered to the location monitoring service:
from CllLocationManager Class Reference
If you start this service and your application is subsequently
terminated, the system automatically relaunches the application into
the background if a new event arrive...
Add CLLocationManagerDelegate in header file.
make sure u added
locationManager.delegate = self;
try increasing the radius and check.
First of all increase the radius you are giving for that particular location and check again if it does not work then by following some easy steps provided in this tutorial you can easily implement Geo-Fencing in your app.
Reference: Apple Documentation
You define a radius of 15m. That is too small. First, try with 50m or more. Look at the map app, if you really have entered that region.
Furthermore, I hope you meant "send to background", instead of closing.
make sure you have set your app to be allowed to run in background? (via plist)

Notification from Background Geofencing in iOS 5?

Is it currently possible to create an app that "reminds me when I get to work, Siri" right now ? Or the app needs to be running to apply geofencing ?
Yes, it is possible by using the CLLocationManager's startMonitoringForRegion
which will call your App when entered/left a certain "fenced" geo-area.
BUT since the user's location is/will be used, the location icon will appear for as long as this call has yet been canceled (by the matching stopMonitoringForRegion)
(on iOS6 this icon will be replaced with a different location icon for "regional" location instead of regular location use - looks like an outline of the current icon)

Using core location on iphone simulator

I am developing an GPS based app. So I was wondering how could I simulate location on iphone simulator?
I downloaded an sample app locateMe. This app does not work on simulator. Does simulator not support location api?
Any help would be appreciated.
Update:
Xcode 4.2 with iOS 5 supports GPS positioning.
Select the Simulator -> Debug -> Location -> Custom Location...
Previous Version
No the simulator does not support it. So for GPS you have to install the application in the device to check it.
Simulator is gonna give you longitude and latitude as the address of Cupertino Where the headquaters of apple is.
So you have to use device only.
Happy Coding
According to the documentation, when using the simulator:
"The relocation reported by the
CoreLocation framework in the
simulator is fixed at the following
coordinates (accuracy 100 meters),
which correspond to 1 Infinite Loop,
Cupertino, CA 95014.
Latitude: 37.3317 North Longitude:
122.0307 West"
So, in practical terms, you should be able to build the app but you'll be unlikely to do anything useful with it.
You might wanna check out my FTLocationSimulator at http://github.com/futuretap/FTLocationSimulator
It reads a KML file generated by Google Earth to provide faked location updates. It also updates the blue userLocation dot in a MKMapView with the simulated location updates.
In Xcode 4.2 we can simulate . There is a location symbol on the debug area (while you run the app). There are some predefined locations . Also we can add new GPX files
The solution was to subclass CLLocationManager and define a new delegate #protocol, called DLocationManagerDelegate.
It is designed to be a simple drop-in replacement for CLLocationManagerDelegate that compiles down to a very thin layer when deployed on an actual device.
When running on the device it will return data as normal using CoreLocation, but in the simulator it will read latitude and longitude from a text file (defined in the DLocationManager.h file).
I hope this helps, the implementation is on the simple side and you have to startUpdatingLocation and stopUpdatingLocation to update the display.
http://code.google.com/p/dlocation/