Creating a nice little phonegap build for ios at the moment, runs fine in the browser, however, when I compile it in Xcode and run in the simulator the history.back() I'm using doesn't work.
I need the history.back() in order to create a back button on each page in the app.
Does anyone know why this may be the case, or an alternative solution.
More information: phonegap build using ember js
Yes, exactly. In several version iOS, Android ( old), history.back() seem not working. To fix it, you should try this code ( i find it in JQM ## and it working well for all )
var nav = window.navigator;
if( this.phonegapNavigationEnabled &&
nav &&
nav.app &&
nav.app.backHistory ){
nav.app.backHistory();
} else {
window.history.back();
}
Related
So I have a redirect working, but it's a little janky & I'm hoping to make it less janky :)
I'm using deep linking to basically open the app only....nothing beyond that at the moment.
Below is the redirect for ios. It works ok, but it's throwing a URL error in safari that I have to tap to close before it will redirect to the app store. (This is the case of a user not having the app installed)
So...I know universal linking is what iOS9 is doing, but I'm trying to avoid implementing too much on the native code side. All I've done is add my custom URL scheme to the plist of the app.
So wise internet...is there a better way?
else if(isMobile.iOS())
{
window.onload = function() {
window.location = 'vrbhome://';
setTimeout("window.location = 'https://itunes.apple.com/us/app/vrb/id1066438072?ls=1&mt=8';", 1000);
}
}
else {
document.location.href="http://vrb.is";
}
This error is by (Apple's) design — the only way to work around it is to decrease the timeout enough that the user goes to the App Store before they have a chance to see the error. Unfortunately as of iOS 9.2, users with your app will also be redirected before they have a chance open the app. Universal Links are the solution Apple wishes you to use.
If you don't want to handle too much native code, you could try https://branch.io
The app is built using the ionic framework.
Its been installed on a new device that's using Android 4.4.
Based on this question I used this code to reload the page:
$scope.reloadRoute = function() {
$window.location.reload();
}
This does not appear to work in Android 4.4+
I have tried the other suggestions from that answer, but they do not work for our case.
I tried this:
location.href = location.origin;
It doesn't work. I need it to reload.
I developing an app for iOS and Android using PhoneGap 3.4.0 from the command line interface, and want to make use of the BarcodeScanner plugin. The problem is that the scanner does not actually do anything when called by my app. The camera does not come up. By using console.log with Safari developer tools, I can tell that the scan function does exist and is getting called... it just isn't doing anything.
I installed the scanner plugin like this:
phonegap plugin add https://github.com/wildabeast/BarcodeScanner
In the index.html, included the javascripts like this:
<script src="phonegap.js"></script>
<script src="barcodescanner.js"></script>
In config.xml, added this:
<gap:plugin name="com.phonegap.plugins.barcodescanner" />
When I set scanner variable like this it logs that there is a BarcodeScanner, and it does have a function scan, but then when I call the function scan nothing happens. (the camera does not open).
var scanner = cordova.plugins.barcodeScanner;
console.log(scanner) // => BarcodeScanner
This is how I'm calling the scan function:
scanner.scan( function (result) {
... my code here...
} );
Any ideas? I'd really appreciate any help or pointers in how to get the barcodeScanner to work with PhoneGap.
I´m having the exact same problem.
After I updated my App to support arm64 (iPad Air), I ran into this issue.
A work-a-round:
Push the hardware On/Off button.
Turn on the device again.
Try starting the barcodeScanner.
This worked for me - but the App will not leave my desk before the issue has been fixed properly.
The issue now exists on all of my devices (iPad Mini, iPhone 4S, iPad Air).
The problem was that the version from wildabeast was not compatible with PhoneGap >= 3.2.0.
Use this branch instead: https://github.com/phonegap-build/BarcodeScanner
Install with
phonegap local plugin add https://github.com/phonegap-build/BarcodeScanner
To get it to work, I had to create a brand new app, copy the www folder over, and then install the plugin.
I am using PhoneGap Build to wrap an AngularJS project as a mobile app, it uses InAppBrowser to open Facebook/Twitter OAuth page.
My configuration:
Angular 1.0.8
PhoneGap 3.1.0 on PhoneGap Build
InAppBrowser 0.2.3
Tested with hydration enabled and disabled, same result
Here is the code snippet I used:
// This part code is called from click handler of a button,
// this is the only place that used the PhoneGap API.
var ipwin; // Used in somewhere else
document.addEventListener("deviceready", function() {
ipwin = $window.open("some url", "_blank");
$(ipwin).on("loadstop", function(e) {
var url = e.originalEvent.url;
console.log("loadstop: " + url);
// snipped
});
// Below are testing code added while debugging
var test = function() {
console.log("setTimeout test");
};
setTimeout(test, 2000);
test();
}, false);
This works fine on Android 4.0, however on Android 2.3 the loadstop event does not fire. I also tried loadstart and loaderror, none of them fires. More strangely, setTimeout test only appears in console output once instead of twice. Is there any problem in my code?
After some refactor and changes to the app, the problem is mysteriously gone. Not entirely sure but I think it is because some other scripts in the page conflicted with cordova.js.
I was experiencing similar problems with both PhoneGap 3.0 and 3.1 on Android, reverting to PhoneGap 2.9 made these InAppBrowser events fire again.
It looks like to be a problem with the last phonegap/cordova version 3.1.0.
https://groups.google.com/forum/#!topic/phonegap/e5_5unC2fYs
Try an older version.
this issue happened to me and I did these steps to solve it:
Upgrade your Phonegap version to 3.1
Create a new project
Add your platforms then your plugins
Copy your code again back to www
this should solve your problem
What is the most efficient and reliable method to detect if an app is running in phonegap, or simply inside of a mobile/desktop browser with JavaScript? I am attempting to eliminate any of the issues that prevent me from testing/debugging my phonegap apps in any browser (desktop or mobile), and create a truly universal code base for my apps.
I intend on structuring my functions with phonegap specific calls like so:
if (phonegapisrunning) {
// phonegap specific javascript calls here
}
else {
// standard javascript calls here
}
While searching for a solution I came across this thread:
PhoneGap: Detect if running on desktop browser.
While this thread discusses this issue, I do not see a clear answer to which method is the most efficient/reliable. Should I bind to the onDeviceReady() event? Should I check window.device? Is there a more efficient or reliable way to check if an app is running in phonegap via JavsScript?
And this thread which mentions the Ripple Chrome Plugin:
Phonegap web app in regular desktop browsers
The Ripple tools looks like it could be a valuable tool for testing. But I am trying to make my phonegap apps run in a desktop browser without a plugin.
If it is determined that the app is not running in phonegap, I would then use useragent sniffing to determine if browser is desktop or mobile, and further separate any code if needed.
I've seen many answers about checking the user agent. Though those are useful for comparing which platform on which a page was loaded, they still do not differentiate whether running within a cordova app's browser or within a regular web browser. After a whole bunch of digging in the android cordova javascript file, I found that the following variable is set when running in a cordova app:
window._cordovaNative
Looking through the ios cordova javascript, I found:
window._nativeReady
Throw these alerts in your page before you ever load any cordova javascripts or check any user agents, etc. and compare results between loading from a web browser and loading from a cordova app that gets dynamic content:
alert("Android: " + window._cordovaNative);
alert("iOS: " + window._nativeReady);
I guess the other devices' phonegap files have different global variables, but for now, this is going to work great for me -- I hope it works well for you!
My suggestion is to create/call your javascript functions outside of the onDeviceReady Phonegap call.
Or maybe check what version of Cordova / Phonegap is running e.g.:
var string = device.cordova; // or device.phonegap
if (string == null) {
//do non phonegappy stuff here
} else {
//do phonegappy stuff
}
While it may not be the cleanest solution, a simple and reliable method is to create/set a global variable on deviceready:
var isCordovaReady = true;
Then:
if (isCordovaReady) {
// do cordova/phonegap stuff
}
else {
// do non cordova/phonegap stuff here
}
I posted the top answer for: PhoneGap: Detect if running on desktop browser
Although this isn't heavily documented and somewhat controversial I've been able to use this chunk of code for all my projects:
if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/)) {
document.addEventListener("deviceready", onDeviceReady, false); //phone
} else {
onDeviceReady(); //this is the browser
}
You can modify it a bit to work for your projects like so:
var phonegapisrunning = false;
if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/)) {
document.addEventListener("deviceready", onDeviceReady, false); //phone
//change to true
phonegapisrunning = true;
} else {
onDeviceReady(); //this is the browser
}
Hope this helps !