I am new to iPhone. When I am dealing with location manager I got the first message to access my location
Allow and Don't Allow if I press allow then it works fine.
But I press Don't Allow then it gives me the warning which I have displayed below :
Function,"void CLClientHandleDaemonDataRegistration(__CLClient*, mach_port_t, const CLDaemonCommToClientRegistration*, const __CFDictionary*)",server did not accept client registration 1
Does anyone have a solution for that?
There is no solution, if the user does not allow your app to use the location service there is no way to enforce it.
You can check if you may use the location service:
BOOL result = [CLLocationManager locationServicesEnabled];
if (result) {
dbgPrint(#"Location services enabeld");
} else {
dbgPrint(#"Location services disabeld");
}
Related
I've implemented the possibility of opening VPN connection with IKEv2. The connection works great after I close (kill) the app. However, I want to get the current connection status after I launch the app again. How can I do that?
Unfortunately this returns invalid status when I try to call:
NEVPNManager.shared().connection.status
but I see (and it's correct and it's true) Personal VPN in active state here:
Could you provide how to get actual status of my Personal VPN?
I've resolved this case with this implementation specially for IKEv2
// special case for IKEv2
NEVPNManager.shared().loadFromPreferences { error in
if error != nil {
//
} else {
print(NEVPNManager.shared().connection.status)
}
}
I've added this into my connection manager and now the app handles correctly the status of Personal VPN after relaunch of the app
I am using [CLLocationManager locationServicesEnabled] function to get the status whether location service is enabled or not. I kept code in viewDidLoad method.
if(![CLLocationManager locationServicesEnabled])
{
NSLog(#"No");
}
else
{
NSLog(#"Yes");
}
When I am running this app first time it returns Yes. Why? It should return me No. This is the case when I did not select "Allow" or "Don't allow" options. Means I neither allow nor don't allow but in viewDidLoad I got Yes.
Now I select "Don't allow" and again load the same viewController. At this time at least it should return me No, but still I got Yes. Why?
So much of confusion with CLLocationManager.
Any ideas?
locationServicesEnabled returns whether location service is enabled on settings.. If it is enabled in settings, this function returns YES all the time..
from documentation
locationServicesEnabled
Returns a Boolean value indicating whether location services are enabled on the device.
Discussion
The user can enable or disable location services from the Settings
application by toggling the Location Services switch in General.
You should check the return value of this method before starting
location updates to determine whether the user has location services
enabled for the current device. If this method returns NO and you
start location updates anyway, the Core Location framework prompts the
user to confirm whether location services should be reenabled.
Whether or not user allowed/rejected app permission (in the alertview) doesn't affect the return value of this method.
If you want to know whether user has given application permission to access location, you can use authorizationStatus.
How to turn ON location services through Code in my application if location service is in OFF condition i want it to ON through alertView i have two buttons in alertview cancel & settings
if i click settings it needs to go settings of the device is it possible???
Could anyone help me??
thanks...........
You can't enable location services in code. You just invoke the service, and iOS will seek permission from the user on behalf of your app.
I've had to deal with the same problem but this is just not possible under iOS. You have to check if location services is enabled :
[CLLocationManager locationServicesEnabled];
and if not, ask the user to go to the settings to enable it (through an AlertView for example).
Note that Apple says :
locationServicesEnabled : You should check the return value of this
method before starting location updates to determine if the user has
location services enabled for the current device. If this method
returns NO and you start location updates anyway, the Core Location
framework prompts the user with a confirmation panel asking whether
location services should be reenabled.
But that only seem to work the very first time you check. If the user denies, the confirmation panel is not shown anymore.
You may also check :
switch ([CLLocationManager authorizationStatus]) {
case kCLAuthorizationStatusDenied:
case kCLAuthorizationStatusRestricted:
case kCLAuthorizationStatusNotDetermined:
}
When we use location services in an application, we receive an iOS alert saying the application is trying to use the current location -- Allow/Don't Allow.
Do we have a delegate call back for these buttons?
I want to handle tap on "Don't Allow".
You don't have direct access to that alert.
If the user presses "Don't Allow", or if the app otherwise doesn't have permission to use location services then CLLocationManager will call locationManager:didFailWithError: on its delegate. The error domain will be kCLErrorDomain and the error code will be kCLErrorDenied.
You can simply get the action selected like below:
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (status == kCLAuthorizationStatusAuthorizedAlways || status == kCLAuthorizationStatusAuthorizedWhenInUse) {
[self addRegion];
}
else if (status == kCLAuthorizationStatusDenied) {
NSLog(#"Location access denied");
}
}
make sure to set the delegate of location manager.
You should also check to see if the user has allowed location services for your app before starting the location manager. Use the CLLocationManager class method locationServicesEnabled to check.
Here's the doc:
locationServicesEnabled
Returns a Boolean value indicating whether location services are enabled on the device.
+ (BOOL)locationServicesEnabled
Return Value
YES if location services are enabled or NO if they are not.
Discussion
The user can enable or disable location services altogether from the Settings application by toggling the switch in Settings > General > Location Services.
You should check the return value of this method before starting location updates to determine if the user has location services enabled for the current device. If this method returns NO and you start location updates anyway, the Core Location framework prompts the user with a confirmation panel asking whether location services should be reenabled.
The first time the app tries to get the users location they are prompted with "Would like to use your current location" and they can hit Don't allow or ok. Is there any way to find out if the user has hit ok or don't allow? I'm trying to have the MKMapView show the users current location but I would like to take different actions based on the users selection.
Normally you would think there would be a delegate to get this information but there doesn't seem to be.
Thanks in advance for your help.
Your first call to get the user's location will fail with an error which tells you the user has denied location services. Your CLLocationManagerDelegate method didFailWithError will be called, as below. (The constants are defined in CLError.h)
- (void)locationManager:(CLLocationManager*)aManager didFailWithError:(NSError*)anError
{
switch([anError code])
{
case kCLErrorLocationUnknown: // location is currently unknown, but CL will keep trying
break;
case kCLErrorDenied: // CL access has been denied (eg, user declined location use)
message = #"Sorry, flook has to know your location in order to work. You'll be able to see some cards but not find them nearby";
break;
case kCLErrorNetwork: // general, network-related error
message = #"Flook can't find you - please check your network connection or that you are not in airplane mode";
}
}