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”.
Related
I'm using the App Intents API to provide an automation through the iOS Shortcuts app. When my intent runs, I'd like to be able to decide if I want to open the app (bring it to the foreground) or not. I know openAppWhenRun can be used to open the app, but its value cannot be modified.
I tried using openAppWhenRun, but it does not have a setter. Therefore, I cannot dynamically update this variable to determine if the app should be opened in the foreground or not.
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.
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>
I would like to know how it's possible to develop an app that provide only some settings in the iOS native setting app like a lot of cydia tweak without have an icon on the springboard ?
My goal is just to have some switch and button who send command on my local network.
In iOS your app must have an icon on the springboard.
You can add your app to the Settings App to allow for changing your app settings. The catch is that when these settings are changed, they do not launch your app too send it actions.
Is it possible to mock a location when using Core Location Manager like you can in Android? I want to do this so we can see simulated behaviors when a user is a different location.
If you are using at least Xcode 4.2 and iOS SDK 5+, you can launch your app and in the simulator you can click the debug menu, then click the location option, the click custom location. You can then enter a custom latitude and longitude. They also have options for Freeway Drive, City Bicycle Ride, and City Run these all emulate the device moving.
You can definitely simulate location on the device if you run from Xcode. After the app compiles, installs, and starts running, find the "Debug Bar" at the bottom of the window (or just above the Console, if you have that showing). There is a small "Location" icon that reveals a menu of locations, plus an option to load a GPX file if you want something more complex. You can also edit your build scheme to include a default location in the Run phase (i.e., for every run, not just when you set the location with the menu in the Debug bar).
One thing to note, if you're using your personal device and not a dedicated development device: the custom location Xcode sets persists even after you disconnect from Xcode. So if you leave your desk with your phone, you may find it still thinks it's in whatever location you simulated; restarting will clear this setting, and allow you to use your device normally.