:// Would Like To Use Your Current Location - ios

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

Related

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>

App crashes with __CRASHING_DUE_TO_PRIVACY_VIOLATION__ when trying to access contacts

Upon updating to iOS 10, when trying to access the contacts through plugin cordova-plugin-contacts v2.2.0, the app exits with
__CRASHING_DUE_TO_PRIVACY_VIOLATION__
I don't know what other extra info i can provide right now, just let me know if i can be more specific. Thanx.
Maybe this is of some use: https://stackoverflow.com/a/39416858/592641, but i couldn't find a guide of how to specify those usage descriptions in cordova.
After creating an Xcode project and finding the Info.Plist file, you may try adding NSContactsUsageDescription key, which should accept a string value.
A complete list of Cocoa Keys
Hope that helps!
EDIT
A part from the doc: (which can help you understand why it is crashing)
Important: To protect user privacy, an iOS app linked on or after iOS
10.0, and which accesses the user’s contacts, must statically declare the intent to do so. Include the NSContactsUsageDescription key in
your app’s Info.plist file and provide a purpose string for this key.
If your app attempts to access the user’s contacts without a
corresponding purpose string, your app exits.
My app was missing NSFaceIDUsageDescription key
In short, the usage descriptions need to be specified inside *info.plist
That's no good for Cordova codebase since .plist files are not part of the repository. The simplest way I found to put them inside config.xml is this:
Install cordova-custom-config
Add the following inside config.xml:
.
<platform name="ios">
<config-file parent="NSContactsUsageDescription" target="*info.plist">
<string>Easily invite your friends</string>
</config-file>
</platform>
My Info.plist was missing NSPhotoLibraryAddUsageDescription. There are now TWO permissions associated with the photo library (starting iOS 11):
NSPhotoLibraryUsageDescription - to access the photo library
NSPhotoLibraryAddUsageDescription - write only permission to photo library
I had the first permission prior to iOS 11 when it was the only key needed to use the photo library. Apparently in iOS 11 they added the second and made it required to add photos to the library. So if you support iOS 10 but don't include the second key, you will crash on iOS 11.
All Keys are Here
For me, I was trying to request access to the microphone, but I hadn't defined the Privacy - Microphone Usage Description string.
Go into your Info.plist file, and scroll down to the values that start with Privacy. Make sure you add keys and string values for everything relevant to your app.
I got here with the same error using Kudan AR via Unity, and #NeverHelpless's answer was on target, except the fix was NSCameraUsageDescription (Add to Info.plist with a description string)
If you are clear the issue is when accessing Contacts, then follow instructions posted on above answers.
But if those didn't help you, you may want to read my related answer here on other possible solutions (if you are using Bluetooth on your app):
https://stackoverflow.com/a/60073667/457202

iOS cordova allow location access 'Always'

I am developing an app with Cordova for iOS which includes geolocation functionalities (I use the official plugin https://github.com/apache/cordova-plugin-geolocation). I saw in options of my app that location access can be either set as "Never" or "While Using the App". However some other apps may also the option "Always" as shown in the attached screenshot. I would like to know whether it is possible to also have the option "Always" for Cordova-based applications.
Thanks!
I was using both NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription in my company's Cordova app and it was working. Then, in late 2017, it stopped.
The fix for me has been to add also NSLocationAlwaysAndWhenInUseUsageDescription.
More broadly speaking, note that you need to have a plugin allowing to track location in background as well as make sure that the necessary background mode option is enabled in XCode.
We use the following plugin to do the job:
https://www.npmjs.com/package/cordova-plugin-lents-background-geolocation
This type of plugin is necessary as iOS stops execution of scripts for apps roughly 3 minutes after the display is turned off, regardless of the app foreground/background condition when the display was turned off. This prevents any JavaScript code to run and therefore any GPS tracking based on setInterval or setTimeout will stop working.
I guess "NSLocationAlwaysUsageDescription" key is the one which you are looking for. Check out this link which details the settings to be done in cordova based applications to have constant location access.
I'm using Ionic 2 and had to add the following to my App-Info.plist file. Even though cordova inserts 'NSLocationAlwaysUsageDescription' and 'NSLocationWhenInUseUsageDescription' keys. This only gave a 'Never' and 'While Using App' option on launch. Xcode suggested using the option below and that worked for me.
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app requires background location tracking</string>

Fix Cordova Geolocation Ask for Location Message

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>

IOS App Submission Routing App

I am trying to submit my app for review in Itunes Connect, but when I try to submit it I get an error:
To configure this app as an IOS routing app, upload a routing app
coverage file on the app's Version page in My Apps on iTunes Connect.
To configure your app as an IOS routing app, the app's Info.plist must
contain the MKDirectionsApplicationSupportedModes key.
So in my project, in the Capabilities, the Maps is turned off. I do have the MapKit.framework in my project, as I do utilize the map, however I do not ever show routing information nor provide it in my app. Is the fact that this framework in my project causing this ITunes Connect error, and if so, how do I go about fixing it. And by fixing it, I want it to turn off routing.
My app is not made to provide routing information, nor do I want to set it as an iOS routing app.
Any help would be appreciated.
I am using XCode 6.
I figured it out. In my info plist there was a document type name of MKDirectionsRequest. Removing that solved the problem.
From the apple docs
(To use the features of the Map Kit framework, you must turn on the
Maps capability in your Xcode project.)
above the entire paragraph.(https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40009497)
Location-based information consists of two pieces: location services
and maps. Location services are provided by the Core Location
framework, which defines Objective-C interfaces for obtaining
information about the user’s location and heading (the direction in
which a device is pointing). Maps are provided by the Map Kit
framework, which supports both the display and annotation of maps
similar to those found in the Maps app. (To use the features of the
Map Kit framework, you must turn on the Maps capability in your Xcode
project.) Location services and maps are available on both iOS and OS
X.
Not sure but maybe you only need to turn on mapkit
In my info.plist I had to delete two entries:
1) the document you referenced above - MKDirectionsRequest
and
2) MKDirectionsApplicationSupportedModes - MKDirectionsModeCar which is called "Maps routing app supported modes"
I just faced this exact issue last week.
I had accidentally turned on Map capabilities and turned it off later. Like your case, this didn't fix the issue.
I believe what fixed it was removing MapKit from here.
I was trying other things at the time so try this and if this isn't it then I'll see if something else I changed fix this.

Resources