My code fetches the apigee collection fine when running on the desktop with Chrome browser.
When I turn it into an app via phonegap/android-studio and run it on my android phone it shows my alert: "error fetching remote candidate data" that means fetch returned an error.
Why would this fetch the collection on the desktop but not the phone?
(guest has GET permissions for the collection)
function loadRemoteData() {
endorseds = new Apigee.Collection({
"client": client,
"type": "endorseds",
"qs": {
"limit": 4000,
"ql": "order by order,district,name"
}
});
$.mobile.loading("show");
endorseds.fetch(function(err, data) {
if (err) { alert("error fetching remote candidate data ");
if(lastLocalDate > 0){
loadLocalData();
}
$.mobile.loading("hide");
} else {
alert("remote fetch ok");
localStorage.setItem('endorseds', endorseds.serialize());
if(lastRemoteDate == 0) lastRemoteDate = getToday();
localStorage.setItem('lastdate',lastRemoteDate);
$.mobile.loading("hide");
showMain();
}
});
}
The answer depends upon the version of PhoneGap that you are using. Have a look at the config.xml file. At the bottom (by default) of the file, you should see a line where "something here" was 127.0.0.1/* in older versions of PhoneGap. I'm not sure where it got change (3.2, I believe), but it is now which allows the app to communicate with any web site/application. Change that line to the wildcard and recompile – this should solve the issue.
Related
My goal is to add a biometric option to my nativescript app.
The user gets a prompt in which i'm waiting for his authentication.
if authenticated - I want to console.log("Great"). and if not log "Problem".
I'm building it using Angular + Nativescript, so I registered Fingerprint as as provider, imported it and on constructor decalred:
constructor(private fingerprintAuth: FingerprintAuth);
And for the verifyFingerPrint, when page loads I call:
this.fingerprintAuth.available()
.then((result: BiometricIDAvailableResult) => {
console.log(`Biometric ID available? ${result.any}`);
if(result.any) {
if(result.face) {
console.log("HANDLE FACE WILL BE HERE SOON!");
}
if(result.touch) {
console.log("If not face, then touch id. Let's try it.");
this.fingerprintAuth.verifyFingerprint(
{
title: "Biometric Verification",
message: "Let's just make sure it's you..."
})
.then((data) => console.log("Authenticated, contacting server now...", data))
.catch((e) => console.log("Problem occured while authenticated.", e))
}
} else {
console.log("No Biometric Option is available, try adding one.");
}
});
}
The problem is, I am getting the fingerprint prompt as expected, but after a good or bad verification I never get the console.log part. .then / .catch - both won't log anything
And i'm not getting any errors..
I'm using sidekick,
local build on a Pixel 3 XL API 28 Emulator,
Plugin name:nativescript-fingerprint-auth
Nativescript + Angular Project
What could be the problem..?
Thanks!
I am trying to test my application written in Ionic 2 framework on actual device. The problem is that whenever I try to call my node.js API from device, the call does not even get there. Everything works fine on computer with ionic server command, but I cannot run it on my phone when I use ionic cordova run android. I can run sample applications that do not use my API with no errors.
My API code that allows any origin is following:
app.all('/*', function(req, res, next) {
var origin = req.headers.origin;
res.setHeader('Access-Control-Allow-Origin', origin);
res.header("Access-Control-Allow-Credentials", "true");
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
next();
});
And my code on client side that calls API is:
checkLogin(): Observable<boolean>{
return this.http
.get(`http://localhost:8080/user/loginstatus`, { headers: this.getHeaders(), withCredentials: true})
.map((res: Response) => {
if(res.json()==true){
return true;
}
else{
return false;
}
});
}
Basicly I would like to check if user is logged in so I can set the proper root page in the beggining of the app start. Please help. Thank you in beforehand.
I have a Cordova app that uses the ionic framework. I have many json data files that I put in the www/json folder in my app's file tree. I am using angularJS http calls to access them.
When I test my app in chrome (using "ionic serve" in the terminal) it works fine but when I test it on an android device(nexus 5 with Android 6.0 Marshmallow) it no longer works.
Sample code
function getBookNames() {
return $http.get("..\\bookfolder\\Books.json")
.then(function (data) {//if success than do
return data.data;
}, function (reason) {// if fail than do
// maybe tell the user what happened...
});
}
I have tried adding
var path = "";
if (ionic.Platform.isAndroid()) {
path = "\\android_asset\\www\\";
}
function getBookNames() {
return $http.get(path + "..\\bookfolder\\Books.json")
.then(function (data) {//if success than do
return data.data;
}, function (reason) {// if fail than do
// maybe tell the user what happened...
});
}
when I am debugging the app on my phone I get the following error.
GET file:///android_asset/bookfolder/Books.json net::ERR_FILE_NOT_FOUND
If anyone knows what I am doing wrong or of a better way to access local .json files please let me know. Thanks!
Use slash / character, not backslash \. Also, put bookfolder inside /android_asset/www
$http
.get('/android_asset/www/bookfolder/books.json')
.then(function(response){ return response.data });
I'm using Ionic Framework to build an iOS / Android app which writes sqlite data to a CSV file, then attaches that file to an Email and sends it. The following code works correctly on iOS (actual device iPhone 5).
I don't have an Android device, but in the Android emulator (nexus 5), the file sent never has a file attachment (despite the emulator showing that it does).
Is there a different way I should be writing this code?
I looked at the documentation here, but it does not clarify
https://github.com/katzer/cordova-plugin-email-composer#adding-attachments
$cordovaFile.writeFile(cordova.file.dataDirectory,
"PatientEncounters.csv",
data.join("\n"),
true)
.then(function (success) {
$cordovaEmailComposer.isAvailable().then(function() {
var emailOpts = {
to: [email],
attachments: ['' +
cordova.file.dataDirectory.replace('file://','') + "PatientEncounters.csv"],
subject: 'Patient Encounters',
body: 'A CSV containing Patient Encounters is attached',
isHtml: false
};
$cordovaEmailComposer.open(emailOpts).then(null, function () {
// user cancelled email
});
return;
}, function (error) {
return;
});
}, function () {
// not available
});
My problem was using cordova.file.dataDirectory instead of cordova.file.externalDataDirectory. The mail app in android would not allow attaching files from internal storage.
I'm (newly) using protractor to run e2e cucumber tests.
I got a web-app which is angularJS based. I'm using appium to remotely run the test on a real android device. Here are the versions i'm using :
windows8.1
protractor#1.3.1 (with submodule selenium-webdriver#2.43.5)
appium#1.3.0beta1
android device with 4.4.4
my protractor configuration (extracts), corresponding to https://github.com/angular/protractor/blob/master/docs/browser-setup.md:
currentDeviceUDID = (...);
var appToTestURL = 'http://my.website.com:9000/app/index.html';
exports.config = {
seleniumAddress: 'http://localhost:4723/wd/hub';
chromeOnly: false,
specs: ['features/sample.feature'],
capabilities: {
browserName: 'chrome',
'appium-version': '1.0',
platformName: 'Android',
platformVersion: '4.4.4',
udid: currentDeviceUDID
},
baseUrl: appToTestURL
framework: 'cucumber',
cucumberOpts: {
require: 'features/stepDefinitionsSample.js',
tags: '#dev',
format: 'progress'
},
// configuring wd in onPrepare
onPrepare: function () {
var wd = require('wd'),
protractor = require('protractor'),
wdBridge = require('wd-bridge')(protractor, wd);
wdBridge.initFromProtractor(exports.config);
},
allScriptsTimeout: 30000,
getPageTimeout: 30000
};
As you can see, i have replaced the protractor's webdriver url with the appium webdriver. i start the appium from commandline with "appium &", then i run the test with "protactor cucumbertest.conf"
The phone opens chrome browser and navigates to the url i give it with "browser.get(url)"
the problem is the following:
the call waitForAngular(), which is asynchronously waiting for the website to load and on all open http request (as far as i understand), is not executed sucessfully on the phone. the phone does not react to the call, and the webdriver proxy returns a 500.
Corresponding to https://github.com/angular/protractor/issues/1358, i understood that the waitForAngular() function is mixed in protractor into the calls
['getCurrentUrl', 'getPageSource', 'getTitle'];
Behind waitForAngular() in the file protractor.js is the function below, which is proxied to the phone:
functions.waitForAngular = function(selector, callback) {
var el = document.querySelector(selector);
try {
if (angular.getTestability) {
angular.getTestability(el).whenStable(callback);
} else {
angular.element(el).injector().get('$browser').
notifyWhenNoOutstandingRequests(callback);
}
} catch (e) {
callback(e);
}
};
Additional information: when i stimulate an error on the webdriver (browser) object, the error message points to the chromedriver.exe inside the protractor directory. i dont understand why the error is not from appium's chromedriver
so tldr;
without the successful call waitForAngular, i cannot (stable or at all) access elements on the page on the phone, so not testing. maybe im misunderstanding some fundamental configuration detail here, all hints are welcome.
edit: added appium server logs here: http://pastebin.com/vqBGUdXH
I assume i have identified the problem. Appium and Protractor work fine.
My angularJS app causes the issue. It uses $timeout for polling (im forced on angular 1.07 which has no $interval). This causes protractor to expect the page to be still in the loading stage and not finished. Therefore the function call waitForAngular() never returns and the test timeouts after the specified timeout-timespan.
This behaviour is expected and known, also documented (better read doc first ;) ) at http://angular.github.io/protractor/#/timeouts
The doc suggests the following for continuous polling: replace $timeout with $interval:
If your application continuously polls $timeout or $http, it will never be registered as completely loaded. You should use the $interval service (interval.js) for anything that polls continuously (introduced in Angular 1.2rc3).
For now, i fixed the issue another way: disable the built-in angular sync and manually sync
this.Before(function(next){
ptor = protractor.getInstance();
ptor.ignoreSynchronization = true; //disables waitForangular()
next();
});
Sync method 1:
//at a testcase, wait for an element to be visible with a promise/then
browser.wait(function () {
element.all(by.css('.myCssClass')).then(function (items) {
items[0].getText().then(function (text) {
console.log(text);
});
});
return true;
}
Sync method 2 :
// "eventually" (chai-as-promised) internally uses "promise" (and therefore acts like "then")
browser.get(url);
expect(browser.getTitle()).to.eventually.equal("connect me").and.notify(next);