Getting error when trying to update location - ios

i try to update the user current location, my relevant code is this :
#pragma mark-
#pragma mark CLLocationManagerDelegate
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
float latitude=newLocation.coordinate.latitude;
float longitude=newLocation.coordinate.longitude;
TopStationAppDelegate *topStation=(TopStationAppDelegate *)[[UIApplication sharedApplication]delegate];
topStation.latitudeUtilisateur=latitude;
topStation.longitudeUtilisateur=longitude;
NSLog(#"%f",latitude);
NSLog(#"%f",longitude);
NSLog(#"position updated");
//[locationManager stopUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(#"didFailWithError: %#", error);
}
the didFailWithError method return me this stack:
ERROR,Time,332840118.515,Function,"void CLClientHandleDaemonDataRegistration(__CLClient*, mach_port_t, const CLDaemonCommToClientRegistration*, const __CFDictionary*)",server did not accept client registration 2
2011-07-20 09:35:18.525 TopStation[764:207] didFailWithError: Error Domain=kCLErrorDomain Code=1 "The operation couldn’t be completed. (kCLErrorDomain error 1.)"
Can you please help me there? thanx in advance :)

As the previous comment stated, the simulator version you are working with just won't work for location based stuff. Your best bet (if you are a paid developer) is to download the new Xcode 4.2 that does allow you to manipulate location data and actually use the simulator.
If you aren't a paid developer, you will have to test on device.
Check this post here for some links if you are a paid dev. You can check out the WWDC videos on how to use the simulator for location testing.

Related

iOS app rejected - Your app enables the display of nearby users' locations on a map, but does not have the required privacy precautions in place

My iOS app rejected from apple due to following reason :-
Your app enables the display of nearby users' locations on a map, but
does not have the required privacy precautions in place.
And they are sharing this screenshot of my app with rejection message.
In my app, I am using user’s location for showing near by events on the Map. Also I have enabled option showing user’s location on the Map.
I am using following code for setting up location services into my app.
//Declarting objects in .h file
CLGeocoder *geocoder;
CLPlacemark *placemark;
#property (nonatomic,retain) CLLocationManager *locationManager;
//Calling this method from viewDidLoad for setup location services..
-(void)getUserCurrentLocation
{
geocoder = [[CLGeocoder alloc] init];
self.locationManager=[[CLLocationManager alloc]init];
self.locationManager.delegate=self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
_locationManager.distanceFilter=kCLDistanceFilterNone;
if ([_locationManager respondsToSelector:#selector(requestWhenInUseAuthorization)])
{
[_locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];
}
-(void)StopUpdateLOcation
{
if([CLLocationManager locationServicesEnabled])
{
[self.locationManager stopUpdatingLocation];
}
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLLocation *currentLocation = newLocation;
if (currentLocation != nil)
{
//Saving location
[USERDEFAULT setValue:[NSNumber numberWithFloat:currentLocation.coordinate.latitude] forKey:#"CurrentLocationLatitude"];
[USERDEFAULT setValue:[NSNumber numberWithFloat:currentLocation.coordinate.longitude] forKey:#"CurrentLocationLongitude"];
//Here reverseGeocodeLocation method for fetching address from location
[self StopUpdateLOcation];
}
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(#"didFailWithError: %#", error);
}
Also I have added property “Privacy - Location When In Use Usage Description” with proper message. Also I have disabled the location service when got the location.
Not sure, why they are rejecting app. Did I miss something.?
How can I resolved this issue.?
Any help would be appreciated.
Finally, Got the proper solution for this. Thanks #Anbu.kartik for helping to findout this solution.
I have enabled the option for showing user’s location on the MAP. but didn’t wrote the failure delegate methods for handling, if user’s location not found.
So I write following delegate methods and send an app for approval again. And the app is approved by apple.
- (void)mapView:(MKMapView *)mapView didFailToLocateUserWithError:(NSError *)error{
NSLog(#"didFailToLocateUserWithError %#", error.description);
}
- (void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error{
NSLog(#"mapViewDidFailLoadingMap %#", error.description);
}
So we must have to write failure delegates for handling errors for all the functionalities. So never happens rejection of app related this type of issues.
Hope, this is what you're looking for. Any concern get back to me. :)
Have you added this message to iTunes store description:
Continued use of GPS running in the background can dramatically
decrease battery life.
e.g: check the last line in Google Maps description:
https://itunes.apple.com/us/app/google-maps-navigation-transit/id585027354?mt=8

Get attitude and longitude without using the map

I want to get the current location latitude and longitude without using the map, is it possible to get like that, I am not getting that from searching the internet, can any one help me to find that.
I tried this with using the core location but even I am not got any thing.
please tell me how to find the latitude and longitude, thank you.
//remember to stop before you are done, either here or in view disappearance.
- (void) dealloc
{ [locationManager stopUpdatingLocation]; }
in .h file:
CLLocationManager *locationMgr;
in .m file:on load
locationMgr =[[CLLocationManager alloc] init];
locationMgr.desiredAccuracy = kCLLocationAccuracyBest;
locationMgr.delegate = self;
if ([locationMgr respondsToSelector:#selector(requestWhenInUseAuthorization)]) {
[locationMgr requestWhenInUseAuthorization];
}
[locationMgr startUpdatingLocation];
add following delegates:
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
// Handle location updates
CLLocationCoordinate2D location=newLocation.coordinate;
float altitude = newLocation.altitude;
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
// Handle error
NSLog(#"error: %#",[error localizedDescription]);
}
may you are not authorising the location from user. thats why you are not getting anything
thanks

CLLocationManager kCLErrorDomain Codes?

Using iBeacon and CoreLocation I'm receiving the following error:
Error Domain=kCLErrorDomain Code=16 "The operation couldn’t be completed. (kCLErrorDomain error 16.)
Unless I'm missing it, there doesn't seem to be a clear reference on Apple for what each of the error code means.
Can anyone interpret this error code?
The error calls from:
- (void)locationManager:(CLLocationManager *)manager rangingBeaconsDidFailForRegion: (CLBeaconRegion *)region withError:(NSError *)error{
NSLog(#"%#", error);
}
- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error{
NSLog(#"%#", error); }
Look at the docs for CLError. Value 16 is kCLErrorRangingUnavailable.
The docs say:
Ranging is disabled. This might happen if the device is in Airplane mode or if Bluetooth or location services are disabled.
You can use the CLError enum and the error returned to your location manager to handle location errors in a specific and clear way.
It looks like this:
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
if let locationError = CLError(rawValue: error.code) {
switch locationError {
case .Denied:
println("Location permissions denied")
default:
println("Unhandled error with location: \(error)")
}
}
}
Thanks to #rmaddy for the CLError tip.
Also, make sure that you have Background App Refresh enabled. For some reason with my iPhone 5s on iOS 7.1.1, beacons would not range when Background App Refresh is disabled, even if my app is in the foreground. Turning on App Refresh caused beacons to range again.

monitoringDidFailForRegion calls only on ipad

I have developed ios application which is supports for both iphone & iPad.
In that application I have integrated location tracking feature.
Here is how I implemented it.
//start monitoring for region for checked in location
CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(latitude,longtitude);
regionalMonitor = [[CLRegion alloc] initCircularRegionWithCenter:centerCoordinate radius:REGIONAL_MONITOR_RADIOUS identifier:#"checkedIn"];
[locationManager startMonitoringForRegion:regionalMonitor];
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
NSLog(#"didEnterRegion");
}
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
NSLog(#"didExitRegion");
}
- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{
NSLog(#"Region monitoring failed with error: %#", [error localizedDescription]);
}
This methods are perfectly working in iphone application. But when I try to executes them in ipad
monitoringDidFailForRegion
method will be called. But it works perfectly in ipad simulator.
Is there any particular reason for it, or is this device oriented bug. because if I comment
[locationManager startMonitoringForRegion:regionalMonitor];
Then it will not called monitoringDidFailForRegion method
log message - Region monitoring failed with error: The operation couldn’t be completed.
Thanks
I'm pretty sure that geofencing is not supported on WiFi iPads, or at least older ones.
Try printing the value of [locationManager isMonitoringAvailableForClass:CLRegion]. If that is true (1), than it should work. Otherwise, it's unsupported on the current device.

CLLocationManager - Calculate real time speed on iPhone

How can I calculate real time speed on device? I've googled a lot but all I got is to calculate distance and speed after completion of journey. Can I calculate speed at runtime?
Suggestions will be much appreciated.
Thanks in advance.
here CLLocationManager class provide different field of location like, Latitude, Longitude,accuracy and speed.
i use CoreLocationController so for location update i call this bellow method
you can get current speed in - (void)locationUpdate:(CLLocation *)location method like bellow
- (void)locationUpdate:(CLLocation *)location
{
NSString *currentspeed = [NSString stringWithFormat:#"SPEED: %f", [location speed]];
}
or otherwise bellow is delegate method
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(#"in update to location");
NSString *currentspeed = [NSString stringWithFormat:#"SPEED: %f", [newLocation speed]];
}
also you can get example from this link...
http://www.vellios.com/2010/08/16/core-location-gps-tutorial/
i hope this help you...
:)
There is a delegate CLLocationManagerDelegate add it to your controller header file.
Initialize Location Manager and set the delegate where you implement the delegate method for location Manager like this
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self; // send loc updates to current class
and you can write method in your class
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(#"Location Speed: %f", newLocation.speed);
}
That's it you will get your location updates in the above method with the speed also, and it will trigger as frequent as possible.

Resources