didUpdateLocations delegate method not call in iOS 5.1 and earlier - iphone

I am using CoreLocation Framework for getting latitude and longitude in my project.
I have implement this delegate method in my .m file
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
NSLog(#"Locations : %#", locations);
}
But in iOS 5.0 & 5.1, this method is not call.
and in iOS 6.0 or later it's call properly.
so how to call this method in iOS 5.0 or later.

didUpdateLocations: did not exist in ios 5 or earlier. If you want to support those ios version then just use the deprecated didUpdateToLocation:fromLocation. Even though it is deprecated it still works in ios 6 and 7. That's the simplest solution.
You could have delegate methods for both, but that gets more complicated to manage. If you don't need to build track logs in the background then you don't really need didUpdateLocations: it was created to save battery power while collecting multiple points when running in the background.

See this answer...This method for iOS 5 (deprecated on iOS 6)and old version.
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
This method for iOS 6 and later version..
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations

Refer:
http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManagerDelegate_Protocol/CLLocationManagerDelegate/CLLocationManagerDelegate.html
As you can see locationManager:didUpdateLocations: is available only in iOS 6.0 and later.
You can always get the recent updated location from
CLLocationManger's location
property.

Related

How can CLLocationManager call correct delegate methods depending on iOS version

In iOS 5 , delegate method is
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
where as in iOS 6 method is
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
My app supports both version. How CLLocation manage will know which method it should call ?
Do I need to add some #if def ? If yes , can anybody tell me how can I write this.
Thanks in advance.
You can use
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation;
You can build using iOS 6 SDK and set the deployment target to support iOS 5 as well. In case if it doesn't work, you can try implementing this method and call - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
inside that(You can implement this iOS 6 method as well, so that in case of iOS 6 it calls this method directly). You can create an array out of newLocation and oldLocation and pass to this. But I dont think that will be needed. You can test it out in both devices.

MKMapview showing current location wrong

I am using MKMapView and it is showing my current location. in india it is showing well and exact what in google map but in US current location is showing wrong.
i am using
- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
any help please ?
If you are using an MKMapView you can use its delegate method mapView:didUpdateUserLocation:
You need to set showsUserLocation property of your map view to YES.
Then the map view uses CoreLocation framework to determine current location.
It tracks userLocation by itself whenever it receives location updates and updates it periodically.

location problem in IOS4

i am using location in my app and tested it with IOS 3 simulatior it works fine also on device it works fie.
but when tested it on IOS4 simulator it crashes..and unable to find location
I know that the location on simulator is of infinite loop cupertino california.
but it is not working in IOS4...
and i don't have Iphone4...So can't test further
please help
Maybe the simulator can't retrieve the default CLLocationManager location.
You can try this:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
location = newLocation.coordinate;
// Manually setting a default location for simulator only
if(TARGET_IPHONE_SIMULATOR){
location.latitude= 45.00;
location.longitude= 45.00;
}
}

CLLocationManager Delegate changes in iPhone OS 4.0

I have to run my app using iPhone OS 4.0. but while I am running my app the CLLocationManager delegate is not getting called.
The delegate method is
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
}
I can probably help, as I've been dealing with CLLocationManager successfully on iOS4 on a 3GS device, but I need more information.
1) Did you alloc/init the CLLocationManager previously and call startUpdatingLocation? Please include that code, we may be able to help. Specifically, where/how you are setting the delegate? Also, make sure someone is retaining your delegate class so that way you're able to receive the calls. CLLocationManager will not retain the delegate.
2) Are you testing on a device, or on the Simulator? If you are testing on a device, which device?

iPhone: Application Testing and Core Location

I'm trying to implement Application Tests as described here. So far, so good, but i fail to test, for instance, the location of the device using Core Location. I have added the appropriate Framework to the Target, and have initiated the update of location, but i have no clue of how to wait for the location to be loaded, the test suite just ends before the second thread finish. Please help me to find a way to test this sort of things.
If you're relying on CLLocationManager you can implement these two delegate methods in CLLocationManagerDelegate:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
Then you set the CLLocationmanager delegate and tell it to startUpdatingLocation. If you get didUpdateLocation (with oldLocation set to nil) it means you now have a location and you can consider the test a success (make sure you turn off updating). If you get the other one there was a location-manager error.
If you're relying on MapKit and are using MKMapView's user-location update mechanism, then take a look at my response to this question and implement the observer section (observeValueForKeyPath) to be notified when the map has a location (success) or implement MKMapViewDelegate's mapViewDidFailLoadingMap to be notified if there was an error.