iOS cordova allow location access 'Always' - ios

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>

Related

React Native app asks iOS location permissions on first launch, but 0 references to geo/location code anywhere inside

So I have a React Native app, and when testing in iOS, on first launch it always asks for location while in use (within 1 second of opening). ie. "Allow XXX to access your location while you are using the app?" permission dialog.
I am using react-native-permissions for other stuff, but I've searched and searched my code and have 0 references to "geolocation","location","navigator",etc. Basically there no location code or geolocation code anywhere to be found.
Looking for help on how to diagnose this crazy issue. In my NPM modules, again nothing crazy there either that would depend on location. I've even deleted the "NSLocationWhenInUseUsageDescription" from info.plist and app still launches, doesn't crash and never prompts location dialog!
(This is on iOS 11.3)
Looking for advice.
Thanks
Check your Info.plist, you probably have either of these keys, or both:
NSLocationAlwaysAndWhenInUseUsageDescription
NSLocationAlwaysUsageDescription
As a result iOS will prompt for location access as soon as you launch your app.

Android things DP6 Intent with android.provider.Settings.ACTION_SETTINGS does not work anymore

I was using the intent with android.provider.Settings.ACTION_SETTINGS to show the system settings screen from inside my app, to allow the user to configure certain details, like a bluetooth keyboard or adjust the timezone. This was working very well in the DP5.1.
But now in the DP6, the intent
startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
Does not work anymore. No exception is logged in the console.
Any workaround on this?
THe option to install the apk after configuring the device with the IOT_LAUNCHER screen is not very practical for me. Because I want to deliver an image with a bundle, and my app will be started automatically, not allowing the user to see the IOT_LAUUNCHER screen.
Thanks.
In DP6 the Settings application is either deprecated or removed. APIs to modify the screen or time have been added.

Unable to simulate location on Xcode Version 9.0.1 (9A1004)

I'm working on a project where it's very often necessary to change the user's location, of course I included all the necessary data to simulate the location from the very beginning of the project. Today Xcode does not pretend to be a custom location, I decided to try to simulate one of the standard locations (for example San Francisco), but when I launch the application on a real device, my real location is displayed on the real device. I tried to run the application on the simulator, but got the same result. I did a clean project, rebooted the real device (iPhone 7), rebooted Xcode but it did not give results. I read a few topics, but they all relate to the fact that the developers did not include the simulation of the location in the scheme. How can I fix this problem? Thank you.
Update: I've updated Xcode, now I'm using Version 9.1 (9B55), but this did not fix this bug. Sometimes (once a week approximately), Xcode refuses to simulate even standard locations from the list (for example San Francisco). Although the menu above the consoles shows that the location simulates.
Info.plist contains
<key>NSLocationWhenInUseUsageDescription</key>
<string>Turn On Location Services to allow App to show you Events near you.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Turn On Location Services to allow App to show you Events near you.</string>
<key>NSLocationUsageDescription</key>
<string>Turn On Location Services to allow App to show you Events near you.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Turn On Location Services to allow App to show you Events near you.</string>
Update 1: Xcode does not simulate the location only on a real device (iPhone 7), two weeks ago there was no such problem. When I call CLLocationManager to show an alert, this alert on the real device is not shown at all. I repeat, this problem does not always repeat, this can happen once a week, but no methods help to restore this possibility to a working state.
I got the same problem and here's my work around.
You know the Location Services is not working when you don't see the arrow on status bar when you request location. So just turn Location Services off and on again. I guess this is a bug.
Go to Phone Settings > Location Services... then turn it off and on.
Xcode > Debug > Location Simulation
Simulator > Debug > Location > Custom Location (this will take what you set from step 2.)
You should see the arrow on status bar when you request location. If not... try the steps again.
First of everything ... Warning! , read this (from apple):
You are required to include the NSLocationWhenInUseUsageDescription and NSLocationAlwaysAndWhenInUsageDescription 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.
Anyway, i just suggest make a simple test.
Make sure that you set Allow Location Simulation on the Run Scheme for your Debug Build Configuration on your target-
Run your App, switch to the Map app on simulator (is is the rfirst time you use, make sure you accept allow location dialog). -
Change the location on the location icon on Xcode (see below), and check that the map move to that location-
If everything is ok, the map app must show selected location
If your app is not able to follow same behaviour, maybe you are missing something. Further reading:
About Location Services and Maps
CoreLocation Framework Reference
Cheers.

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>

GPS turn off when my app (phonegap 3.1) go in background

Is it possible to take gps on when phonegap (iOS) app is in background?? In my app gps go off after some seconds. I use phonegap 3.1, backbonejs, requirejs, jquerymobile...
Some plugins???
thank's!
To keep your app running in the background on iOS, you need to build it using Xcode in order to set a project property which will allow your app to receive location updates while in the background. As far as I know, Phonegap Build does not allow you to do this and does not do it for you.
You can either manually edit the project .plist and add the key “UIBackgroundModes” key with a value of “location” or, with your project open in XCode, add the "Required Background Modes" key with a value of "App registers for location updates". This will cause iOS to trigger the JS callback function you have registered with navigator.geolocation.watchPosition() each time a location update is received.
See this page for details about iOS project keys.
See this page for how to set the background modes key in XCode. The value you want to select is “App registers for location updates”.

Resources