Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location Services not working in iOS 11

I just rebuilt my app with the iOS 11 SDK in an attempt to remove the blue banner that is now always appearing. I thought - "Brilliant, that worked", only to discover that location services are now not working at all.

The application used to work with iOS 10 - Has anybody heard anything?

like image 208
William George Avatar asked Jun 07 '17 23:06

William George


People also ask

How do I enable location on my iPhone 11?

Go to Settings > Privacy > Location Services. Make sure that Location Services is on.

Why is Location Services not working?

Set the location permission to 'Allow all the time' or 'Allow only while using the app. ' Further, if your phone is running on Android 12 or above, you'll also see an option to enable Precise Location. Make sure you enable it to improve location accuracy.

Why can't I use Location Services on my iPhone?

Go to Settings > Privacy > Location Services > Location Services AND any apps that are enabled. If they are greyed out, check if you have any restrictions on. Go to Settings > General > Restrictions to check.

Why can't I see someone's location even though they are sharing it on iPhone?

It's probably a problem with your friend's phone The most likely problem, for example, is that the other iPhone might not have cellular or WiFi reception. In addition, that other phone could be turned off, or your friend might have turned off location services in Settings.


2 Answers

It would appear that apple have added yet another privacy feature. The user is now able to override our requestAlwaysAuthorization and downgrade it to requestWhenInUseAuthorization - Which means as a developer we now have to supply both descriptions in the Info.plist

I found that they have added a new key NSLocationAlwaysAndWhenInUseUsageDescription

/* *      Either the NSLocationAlwaysAndWhenInUseUsageDescription key or both the *      NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription *      keys must be specified in your Info.plist; otherwise, this method will do *      nothing, as your app will be assumed not to support Always authorization. */ 

However, upon using this new key - the location service still didn't work, upon further searching I found this gem mixed in with all the extra debugging information:

This app has attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain both NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription keys with string values explaining to the user how the app uses this data

Which directly contradicts the the comment that I found in the updated CLLocationManager.h file. So I've created a radar.

Good news, if you follow the advice of the debugging console, IE. add both the new key NSLocationAlwaysAndWhenInUseUsageDescription and one of the old keys NSLocationWhenInUseUsageDescription, locations services will start to work again.

like image 128
William George Avatar answered Oct 25 '22 05:10

William George


Just to add the steps on fixing this:

2 ways to do it:

A) The easy way: Select your Info.plist file, add the properties, note that they start with PRIVCY instead of LOCATION... therefore, the exact names of these variables starts with "Privacy - Location ... " etc, add each here, and describe how the user would be seeing this on the warning.

B) The hard / interesting / programatic way (I like this way more):

Right click on your Info.plist for your app, and then select "View source code", you should see it all in XML,

Follow the other ...... format, and add these properties as follows:

<key>NSLocationAlwaysUsageDescription</key> <string>Program requires GPS to track cars and job orders</string> <key>NSLocationAlwaysAndWhenInUseUsageDescription</key> <string>Program requires GPS to track cars and job orders</string> <key>NSLocationWhenInUseUsageDescription</key> <string>Program requires GPS to track cars and job orders</string> <key>NSMicrophoneUsageDescription</key> <string>This app uses your Microphone to allow Voice over IP communication with the Program Admin system</string> 

Save, and then right-click on the info.plist file, and then select Property list, this should view the file back into the default view.

EDIT:

Another member asked for code, here it is:

1) On your .H file, add:

@property (strong, nonatomic) CLLocationManager *LocationManager; 

2) On your .M file add under ViewDidAppear() function:

_LocationManager = [[CLLocationManager alloc] init]; [_LocationManager setDelegate:self]; _LocationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation; _LocationManager.pausesLocationUpdatesAutomatically = NO; [_LocationManager requestAlwaysAuthorization];  _LocationManager.headingFilter = 5; _LocationManager.distanceFilter = 0;  [_LocationManager startUpdatingLocation]; [_LocationManager startUpdatingHeading]; 

This what works fine for me, hopefully the code would work for you too.

Regards

Heider

like image 40
Heider Sati Avatar answered Oct 25 '22 05:10

Heider Sati