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.
Related
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
I have a set of Estimote beacons. When I use the estimote sdk, I can range for beacons and use it. But the problem is, when I use iOS SDK for monitoring and ranging, didRangeBeacons is not called at all.
I have started ranging as shown below. When I checked using breakpoint, the function is called.
- (void) locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
switch (state) {
case CLRegionStateInside:
[self.beaconManager startRangingBeaconsInRegion:self.beaconRegion];
NSLog(#"Region CLRegionStateInside");
Please make sure you have gone through the following checklist:
You have entered NSLocationAlwaysUsageDescription in your info.plist
Your property self.beaconRegion is a CLBeacon Region who's UUID matches the UUID you are looking to detect.
Your device is iPhone 4S or newer, is on iOS 7 or higher, and has bluetooth turned on
I would change the code to look something like this:
- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(nonnull CLRegion *)region {
CLBeaconRegion *beaconRegion = (CLBeaconRegion *)region;
if (beaconRegion.major && beaconRegion.minor) {
} else {
switch (state) {
case CLRegionStateUnknown:
// Handle this case when bluetooth is off.
break;
case CLRegionStateInside:
NSLog(#"Inside %#", region);
if (![self.locationManager.rangedRegions containsObject:beaconRegion]) {
[self.locationManager startRangingBeaconsInRegion:[[CLBeaconRegion alloc] initWithProximityUUID:beaconRegion.proximityUUID identifier:beaconRegion.proximityUUID.UUIDString]];
}
break;
case CLRegionStateOutside:
NSLog(#"Outside %#", region);
break;
}
}
}
You only need to range on the UUID, because that will pick up all beacons that match that UUID regardless of major and minor. Also note that you should only attempt to start ranging if you are not already ranging to avoid the extra function call
I identified a strange behaviour on my app using CoreLocation. I'm using the region monitoring functionality but, after authorising the location services (via popup or settings->Location Services) region monitoring fails (The operation couldn’t be completed. kCLErrorDomain error 5.). If I close the app and restart (therefore already authorised) everything works as expected.
My code looks like this:
-(void)initializeLocationServices
{
NSLog(#"Started location services");
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
locationManager.pausesLocationUpdatesAutomatically = NO;
[locationManager startUpdatingLocation]; // to show authorisation popup
}
-(CLCircularRegion*)createRegion
{
// Test coordinates
CLLocationDegrees latitude = 50;
CLLocationDegrees longitude = -1;
CLLocationDistance radius = 50; // meters;
// If radius is too large, registration fails automatically, so limit the radius to the maximum value
if (radius > locationManager.maximumRegionMonitoringDistance) {
radius = locationManager.maximumRegionMonitoringDistance;
}
CLCircularRegion* region = [[CLCircularRegion alloc] initWithCenter:CLLocationCoordinate2DMake(latitude, longitude) radius:radius identifier:#"TEST"];
region.notifyOnEntry = YES;
region.notifyOnExit = YES;
NSLog(#"Created region");
return region;
}
-(void)monitorProximity
{
CLRegion *region = [self createRegion];
// Check if support is unavailable
if ( ![CLLocationManager isMonitoringAvailableForClass:[CLRegion class]]) {
NSLog( #"Failed to initialise region monitoring: support unavailable");
return;
}
// Check if authorised
if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorized) {
NSLog( #"Failed to initialise region monitoring: app not authorized to use location services");
return;
} else {
NSLog(#"Started monitoring proximity");
}
// Clear out any old regions to prevent buildup.
if ([locationManager.monitoredRegions count] > 0) {
for (id obj in locationManager.monitoredRegions)
[locationManager stopMonitoringForRegion:obj];
}
[locationManager startMonitoringForRegion:region];
}
-(void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
{
NSLog(#"Started monitoring for region: %#", [region description]);
[locationManager requestStateForRegion:region]; // check if already inside region
}
-(void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{
NSLog(#"Failed to start monitoring for region: %#", [error localizedDescription]);
}
-(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
NSLog(#"didDetermineState");
if (state == CLRegionStateInside) {
NSLog(#"inside");
return;
} else if (state == CLRegionStateOutside) {
NSLog(#"outside");
} else {
NSLog(#"unknown");
}
}
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
NSLog(#"didEnterRegion");
}
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
NSLog(#"didExitRegion");
}
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
NSLog(#"Monitoring authorisation status is now: %#", status == kCLAuthorizationStatusAuthorized ? #"authorized" : #"not authorized");
if (status == kCLAuthorizationStatusAuthorized) {
[self monitorProximity];
}
}
Am I doing something wrong here? Do I have problems with the flow after didChangeAuthorizationStatus gets called?
From other user reports, it seems that kCLErrorDomain 5 is a 'catch all' for region monitoring fails; it doesn't provide much useful information. I believe that your issue is being caused by the line
[locationManager requestStateForRegion:region]; // check if already inside region
which you're calling from inside the delegate method didStartMonitoringForRegion:
I saw something very similar in my own project and taking this line out (or delaying its execution for a while) solved the issue. My best guess is that iOS is still doing running some internal region monitoring code when this delegate method fires, so it's not an appropriate time to call requestStateForRegion:
Try taking this out and see if it is the answer.
kCLErrorDomain code/error 5 means that you have tried to monitor more than 20 CLRegions.
Descriptio here
see startMonitoringForRegion description It says:
An app can register up to 20 regions at a time. In order to report region changes in a timely manner, the region monitoring service requires network connectivity.
kCLErrorDomain 5 is a catch all that can mean many different things.
One of the sources is when you call [locationManager requestStateForRegion:region] which is necessary when you first monitor for a region to know if you're already in the region or not. This is because the didEnter region will only be called when you actually enter the region. Usually this means the first time you monitor for the region, you must wait 5 seconds until the region is not detected, and only then will didEnter region fire off the next time you're in the region.
There are many different reports of causes to the problem:
Ensure no more than 20 beacons are being monitored
5 means "regionMonitoringFailure". Ensure the radius is not too large (not relevant for beacon monitoring).
Ensure location updates are registered
Omit calling requestStateForRegion, however I described above why it's necessary to do so.
Restarting device and bluetooth may help
Try with 30 second delay
None of these worked for me, however. I think my root cause was similar to the iOS 7.1 bug where it just randomly stopped working on some devices. I tried the restart and restart of bluetooth, nothing helped.
Not sure what changed, but I just tried again the next day and it started working.
Basically you may want to try a different device until this one starts working again.
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.
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.