Fix Cordova Geolocation Ask for Location Message - ios

Does anyone have experience using cordova, html and know how to fix this geolocation message issue for iOS? I just want the message to say the app name followed by the line, "would like to use your current location."
Current Geolocation Message:
///Users/kklsndksjladn/Library/Developer/CoreSimulator/Devices/FAF7EE4C-40BA-430A-80D5-5C84B07D970D/data/Containers/Bundle/Application/DAE305B6-C6DD-438B-B4D7-9B183A8B2D97/HelpME.app/www/index.html
I've tried various solutions from stack overflow and other websites. I implemented the navigator.geolocation.getCurrentPosition(onSuccess, onError); code, included my cordova.js file in every html page, made sure <script> src=cordova.js</script> appears first in my index.html page, included the geolocation tag in my config.xml file and tried playing around with my plist. Someone please help!!!!
-Thanks

In addition to the answer from DaveAlden, I had to remove the old version of the geolocation plugin and add the new one. Then I had to remove/add the Cordova iOS platform. Only then could I add NSLocationWhenInUseUsageDescription to the .plist file with success.
First, remove/add the geolocation plugin:
cordova plugin rm org.apache.cordova.geolocation
cordova plugin add org.apache.cordova.geolocation
Second, remove/add the iOS platform:
cordova platform rm ios
cordova platform add ios
Last, add NSLocationWhenInUseUsageDescription to the .plist. Open /platforms/ios/{project}/{project}-Info.plist and add the following:
<key>NSLocationWhenInUseUsageDescription</key>
<string>[App Name] would like to access your location when running and displayed.</string>
See this iOS Developer Library link for detailed information regarding NSLocationWhenInUseUsageDescription versus NSLocationAlwaysUsageDescription versus NSLocationUsageDescription.
Location permission alert on iPhone with Cordova is a possible duplicate.

To customise the iOS location permission request message, you need to add a property to your project's .plist.
If your app requests permission to use location in the background, you want the following key (set the string value to anything you like):
<key>NSLocationAlwaysUsageDescription</key>
<string>My app requires constant access to your location, even when the screen is off.</string>
If your app only uses location while in the foreground, then add the following key:
<key>NSLocationWhenInUseUsageDescription</key>
<string>My app requires access to your location when the screen is on and the app is displayed.</string>

Related

:// Would Like To Use Your Current Location

I am build an mobile app using ionic capacitor. In the webview, I am using javascript:
navigator.geolocation.getCurrentPosition
When the user first time install and open the app, it pop up an alert as below:
Now Apple asked me to change the description :// to be more meaningful.
Please revise the purpose string in your app’s Info.plist file for the
location to explain why your app needs access.
You can modify your app's Info.plist file using the property list
editor in Xcode.
I tried all location related properties but none of them are changing the description in the alert box.
Ideas/help please.
That's a WKWebView bug, you should report it to WebKit team, it's supposed to show the name of your app, but it's not
https://bugs.webkit.org/
You can use Geolocation plugin instead of web geolocation
The problem is related with the plugin you are using to get the Geolocation.
Using Angular
I switched
from: import { Geolocation } from '#ionic-native/geolocation/ngx';
to: import { Geolocation } from '#awesome-cordova-plugins/geolocation/ngx';
So, a plugin change worked for me!
Assuming you're using the geolocation plugin, you need to change privacy descriptions in Info.plist as per the guide. Look for these two keys:
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription

iOS App not showing location permission in app settings

I'm developing an app for iOS and Android using Xamarin where I need to use the user's location but the location permission isn't displaying on within the app settings.
I've added:
<key>NSLocationAlwaysUsageDescription</key>
<string>Description of usage</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Description of usage</string>
to my Info.plist file but it isn't showing the location settings in my app settings.
I've also added the permissions for Media Library and Camera and they're showing perfectly fine so I'm not sure why location is any different.
Per some advice online I've also tried re-installing the app and rebooting the device, but neither have changed what I'm seeing.
I'm testing this on iOS 12.3.1.
Thanks
From the document:
To access location services on iOS, you must set the following keys in Info.plist:
iOS 11
NSLocationWhenInUseUsageDescription – for using location services when the app is in use
NSLocationAlwaysAndWhenInUseUsageDescription – for using location services at all times
iOS 10 and earlier
NSLocationWhenInUseUsageDescription – for using location services when the app is in use
NSLocationAlwaysUsageDescription – for using location services at all times
To support iOS 11 and earlier, you can include all three keys: NSLocationWhenInUseUsageDescription, NSLocationAlwaysAndWhenInUseUsageDescription, and NSLocationAlwaysUsageDescription.
See this thread for more information: location-services-not-working-in-ios-11
do not fight, just use this plug in
https://github.com/jamesmontemagno/PermissionsPlugin/issues/93
Turns out the problem is I'm just a moron.
I was using the Permissions Plugin and setting NSLocationWhenInUsageDescription, NSLocationAlwaysUsageDescription and NSLocationAlwaysAndWhenInUsageDescription but using PermissionsPlugin I was only checking Location, not LocationAlways and LocationWhenInUse.
Thanks to anyone who tried to help me.

ionic 3 - iOS policy location permission modal alert message

I develop an app that uses geolocation for iOS using Ionic 3. The app was rejected I need to change the app request for location message.
I follow the iOS quirk mention in cordova geolocation plugin page without luck:
<edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
<string>need location access to find things nearby</string>
</edit-config>
I tried another variable NSLocationAlwaysUsageDescription, and both variables. I uninstall and install again the geolocation plugin. I try many answer to "similar" questions but nothing seems to work.
Somethings to note:
I also use BackgruondGeolocation plugin.
Part of the packages
“#ionic-native/background-geolocation”: “^4.12.2”,
“#ionic-native/core”: “~4.11.0”
“#ionic-native/geolocation”: “^4.12.0”,
…
“ionic-angular”: “3.9.2”
I notice that if i add the <edit-config> entry at the end of <platform name="ios"> it gives me a conflict message when building but it ends, no message if it is at the start. It does not work either way.
Please someone help me.
According to the documentation, you have to add this key to your Info.plist :
NSLocationWhenInUseUsageDescription, NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationAlwaysUsageDescription
You are required to include the NSLocationWhenInUseUsageDescription and NSLocationAlwaysAndWhenInUseUsageDescription keys in your app's Info.plist file. (If your app supports iOS 10 and earlier, the NSLocationAlwaysUsageDescription key is also required.) If those keys are not present, authorization requests fail immediately.

How to change the location access description for an Ionic 2 iOS App? I'm using cordova geolocation plugin for my app

I tried changing in the AppName-Info.plist to the description I want but after the build it gets automatically replaced by the default one over below.
<key>NSLocationWhenInUseUsageDescription</key>
<string>$NSLocationWhenInUseUsageDescription</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>$NSLocationAlwaysUsageDescription</string>
I also tried removing the cordova geolocation plugin and reinstalling as
cordova plugin add https://github.com/apache/cordova-plugin-geolocation.git --variable GEOLOCATION_USAGE_DESCRIPTION="Allow location access for maps"
but still it doesn't change the description. What I still get on my app is $NSLocationWhenInUseUsageDescription as my description.
I'm a little late to this post but I came across it while searching for an answer to the same problem. I ended up adding the following code to my ionic project config.xml file and after building and testing I can confirm that this worked.
<config-file parent="NSLocationWhenInUseUsageDescription" platform="ios" target="*-Info.plist">
<string>This app requires access to your location when the screen is on and the app is displayed to Lorem Ipsum. Your code here.</string>
</config-file>
I also attached a picture showing where that bit of code went in terms of the rest of the file.
Location Permission Example

Cordova iOS location message

I use the plugin cordova-plugin-geolocation. My only issue is that the message prompt to allow location looks like this:
/var/container/bundle/application/xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx/my_project/www/index.html
Would like to use your location.
Is there anyway to have something a little bit sexier, like
my_project would like to use your location
Cheers.
Added some code, for the non believers
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady(){
navigator.geolocation.getCurrentPosition(onLocationSuccess, onLocationError, {maximumAge:3000, timeout:2000, enableHighAccuracy:true});
function onLocationSuccess(){
}
function onLocationError(){
}
}
The solution has changed for cordova-plugin-geolocation: "4.0.0". This is what you need to add in your config.xml:
<edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
<string>need location access to find things nearby</string>
</edit-config>
For more information: https://github.com/apache/cordova-plugin-geolocation
From docs:
iOS Quirks
Since iOS 10 it's mandatory to add a NSLocationWhenInUseUsageDescription entry in the info.plist.
NSLocationWhenInUseUsageDescription describes the reason that the app
accesses the user's location. When the system prompts the user to
allow access, this string is displayed as part of the dialog box. To
add this entry you can pass the variable GEOLOCATION_USAGE_DESCRIPTION
on plugin install.
Example: cordova plugin add cordova-plugin-geolocation --variable
GEOLOCATION_USAGE_DESCRIPTION="your usage message"
If you don't pass the variable, the plugin will add an empty string as
value.
To solve your problem, try:
Uninstall the plugin:
cordova plugin remove cordova-plugin-geolocation
Reinstall with:
cordova plugin add cordova-plugin-geolocation --variable GEOLOCATION_USAGE_DESCRIPTION="my_project would like to use your location"
There are 3 possible reasons for displaying the path to the index.html instead of the name of your app:
You have not installed the plugin (or it's not installed correctly)
You are not waiting for the device ready event to call the plugin
You have not linked the cordova.js file in the index.html
As you say that you have installed the plugin and you are using it on device ready event, then it must be that you have forgotten to link the cordova.js in the index.html or the plugin wasn't installed correctly.
Check that you have the cordova.js linked and if you have it, remove the plugin and add it again, removing and re adding the iOS platform might help too
It seems like the version 3.0.0 of cordova-plugin-geolocation ignores the install parameter
--variable GEOLOCATION_USAGE_DESCRIPTION=""
like Bruno Peres said above.
It works fine for me installing the 2.4.3 version.
If you are targetting iOS 8 and later (I my opinion, no need to target older versions anymore...), there are two keys available for configuration:
NSLocationAlwaysUsageDescription
This key lets you describe the reason your app accesses the user’s location information at all times. Include this key when your app uses location services in a potentially nonobvious way while running in the foreground or the background. For example, a social app might include this key when it uses location information to track the user’s location and display other users that are nearby. In this case, the fact that the app is tracking the user’s location might not be readily apparent. The system includes the value of this key in the alert panel displayed to the user when requesting permission to use location services.
NSLocationWhenInUseUsageDescription
This key lets you describe the reason your app accesses the user’s location information while your app runs in the foreground and otherwise when in use. Include this key when your app uses location services to track the user’s current location directly. This key does not support using location services to monitor regions or monitor the user’s location using the significant location change service. The system includes the value of this key in the alert panel displayed to the user when requesting permission to use location services.
So in your iOS project info.plist file you can add the following:
<key>NSLocationAlwaysUsageDescription</key>
<string>my_project requires constant access to your location, even when the screen is off.</string>
Access location only when app is used
<key>NSLocationWhenInUseUsageDescription</key>
<string>my_project requires access to your location only when being used.</string>

Resources