Phonegap iOS with Geolocation in Background - ios

I have read some of the discussions on geolocation in background on PhoneGap, but am still having problems.
I'm working on an application that uses geolocation services.
On IOS when application is in foreground all works fine. When the application goes to background (after around 30-40 minutes) however the geocoding stops working and I don't get the change position event anymore. During the period in background the application successfully JSON's a time stamp and lng/lat every few seconds to my remote server so I know it's working during that limited period.
My configuration is:
Frame work: PhoneGap 2.5
Devices: iOS (tested on 4, 4s & 5 iPhone & iPad4)
iOS Version: 7.0.4
Xcode: Version 5.0.2 (5A3005)
Plugin:
PowerManagement Plugin for Cordova (2.0+)
by Wolfgang Koller - GOFG Sports Computer
https://github.com/purplecabbage/phonegap-plugins/tree/master/iOS/PowerManagement
startWatch Function:
function onDeviceReady() {
startWatch();
function startWatch() {
var options = { enableHighAccuracy: true, timeout: 3100, maximumAge: 0 };
watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
timerID = setInterval ( updateLocation, 3000 );
}
.
.
App-info plist Includes:
"App registers for location updates" under "Required background modes"
&
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
config.xml includes:
<plugin name="PowerManagement" value="PowerManagement" />
Questions:
I was wondering is there a way to ensure JavaScript in PhoneGap runs continually when the app is in the background?
Do I need to set Wakelock acquired/ release to ensure the Powermanagement plugin work efficiently in iOS?
Could someone suggest a different plugin maybe or config/code I may have missed?
Cheers,
Wayne Gardner
Sydney Australia

Try out mine. Works great for iOS and Android
The plugin has a debug mode where it emits sounds for its life-cycle events (location change, exit stationary-region, and more) which is great for getting instant feedback while field-testing.
https://github.com/transistorsoft/cordova-background-geolocation-lt

I'm not sure but maybe IOS is like Android for this function : Creating an Android Service with Phonegap? (Have phonegap app run even when closed)
So, Javascript will stop when app goes in background or a few sec(or min) after.
Moreover, PowerManagement isn't the solution. PowerManagement allows you to tell the OS : "Hey guy, I have an which need to run even if the phone is lock, so please don't turn off the CPU (or Screen) when I lock the phone.
Maybe try this (only for IOS > 5 and WP8) : https://github.com/katzer/cordova-plugin-background-mode
I'm a IOS pro, I'm an Android Pro and I use Cordova and this plugin (PowerManagement) and it doesn't do what you think.
I hope I help you.
Coco

Related

Webview not call any callback when run on app dual in android 11 (samsung device)

i have a problem with webview when my app run as app dual in android 11 (samsung device).
When i load a url like:mWebView.loadUrl("https://google.com")
I had to set a WebViewClient and override some method like: onPageStarted, onPageFinished, onReceicedError,... But there is no callback was called.
Note: My main app work fine but its dual app is not and it only in android 11.
I had google but I dont have any information more.
I had try some thing like: restart device, update android system webview. But it don't affect
Happy to see any answer!
I had found the answer, the problem relative to Package visibility filtering on Android.
By the document "When an app targets Android 11 (API level 30) or higher and queries for information about the other apps that are installed on a device, the system filters this information by default. The limited package visibility reduces the number of apps that appear to be installed on a device, from your app's perspective."
So in this case package "com.google.android.webview" is not visible with my app when it try to load any url.
Conclusion, you just add this snipe code below in to your AndroidManifest.xml file:
<queries>
<package android:name="com.google.android.webview"/>
</queries>

Cordova App keydown event from external footswitch dosen't work on iOS

I build a Phonegap app and want to use an external footswitch via bluetooth. On Android binding the keydown Event works fine. In Browser, no Problem, but on iOS it doesn't.
I tested this variations:
$(document).bind('keydown',function(event)
$(window).bind('keydown',function(event)
$(document).bind('keypress',function(event)
document.body.addEventListener('keydown', function (event)
Does anyone have an idea what the problem is?
I tested with cli 8 and 9.
Thanks for Help
I do not have enough rep to comment so having to post this as an answer. I believe PhoneGap's UIWebView on iOS requires input focus in order to capture keydown. In a Cordova app I have worked on in the past, we placed an input off the screen with focus so that the input of bluetooth device would be captured and processed from there.
Recently however I have found that on an Ionic 4 app using cordova-ios 5.1.1, WKWebView via this plugin cordova-plugin-ionic-webview and the below RXJS fromEvent I have successfully captured keydown on iOS via a bluetooth device without having to have the input. I have not broke it down to know if this combo or any one of these has anything to do with it. Hope this helps.
fromEvent(document, 'keydown').subscribe((event: KeyboardEvent) => {
});

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>

ionic2 steps to set production ready application, did you know bundle.js file is over 3mil char?

i was surprised to see that app.bundle.js in my ionic app is nearly 3 millions char file !, thats a nice and big framework "nearly 5X size of ionic1" anyhow.
as i'm getting very close to finish my app that i wrote from ground up to make use of angular2 and ionic2 -upgrading from angular1 and ngmaterial-
i'm starting to plan for release and how to turn this into production ready.
what are the side effects of having such big file uncompressed ? it takes my iOS emulated 16sec to bootstrap app ! but i'm thinking its just the emulator problem right ?
did anyone figured out a planned steps to how turn ionic2 app ready for publishing to iOS and android ?
is there anyway i can exclude directives/services/ parts of angular2/ionic2 that my app never uses ?
---Info----
i'm on Ionic Version: 2.0.0-beta.3, angular-2 version: 2.0.0-beta-12

IOS Phonegap Functionality not working first time

I am opening one url in inapp browser. when i return from inappbrowser to my phonegap app. phonegap function like camera,gallery or even device ready is not working. but when i send app in background and resume it then all the functionality is wokring. :(
Where in Android all working fine but in ios not.
I have 3 html pages.from index.html i am opening the page in inappbrowser after i am comming to second.html in which i had use all functionality like camera,gallery.
I had used winload.location for redirection...
I had try lot.
Please Help me .... :(
I had this problem some time ago.
To me was related to the settings of the camera. I used following settings:
quality: 50, // or less for ios as in specifications,
destinationType: parent.window.Camera.DestinationType.FILE_URI, // ! Important
Regards

Resources