I have a json data file I use as my database in my program. Works fine when I run the app in my desktop browser. Also works fine when I send it to voltbuilder and test it on my phone. But when I do a voltbuilder build to an ipa and run it on my phone… the app installs but database is not there.
How do I include this file with my ipa so it is installed with the app on my phone and accessible by the app?
Hi George,
Thanks for the reply and link to Remote Debugging. I have worked a lot on this and tried all of the recommendations and combinations of CSP and my app still does not read the .json file I have for my database. I have no problems accessing my website to retrieve data as well as accessing other sites to retrieve maps. To speed testing I have ben deploying to a local folder. The .json file is there - it is just not being read. I get 5 errors… the first I feel is the problem because the others rely on the json file being read. Here is the first error:
index.html:1 Access to XMLHttpRequest at 'file:///D:/Program%20Files/
NSB%20AppStudio/projects/QuickPlanning.appstudio/
QuickPlanning/airports2.json' from origin 'null' has been blocked by
CORS policy: Cross origin requests are only supported for protocol
schemes: http, data, isolated-app, chrome-extension, chrome,
https, chrome-untrusted.
Does this give you any clues as to where I need to go next?
function ajaxRequest(){
var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
for (var i=0; i<activexmodes.length; i++){
try{
return new ActiveXObject(activexmodes[i]);
}
catch(e){
alert("error");
//suppress error
}
}
} else if (window.XMLHttpRequest) // if Mozilla, Safari etc
{ return new XMLHttpRequest();
}else{
return false;
}
}
function loadDB(){
var mygetrequest=new ajaxRequest()
mygetrequest.onreadystatechange=function(){
if (mygetrequest.readyState==4){
// alert(mygetrequest.status);
if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1){
jsondata=eval("("+mygetrequest.responseText+")"); //retrieve result as a JavaScript object
rssentries=jsondata.items;
// NSB.MsgBox('Loaded <'+rssentries.length+'> airports!');
} else {
NSB.MsgBox("Database not loaded. Report error to developer.");
}
}
}
mygetrequest.open("GET", "airports2.json", true);
mygetrequest.send(null);
}
I call loadDB() when I load my db. It calls ajaxRequest()
Both… it does not read the database in either, local or on my IOS iPhone.
I just did another IOS build with voltbuilder and the problem is still there… it is not reading my .json file. But of course my big concern is I need it on my IOS app.
Thanks George,
Sorry for the delay. I had to figure out how to get to the Remote Console.
First time I ran it I got these errors … I and noticed about rssentries not being an object so I set it as a variable: var rssentries; I don’t know if that is the correct way but then I no longer got the rssentries error.
[Error] Failed to load resource: The requested URL was not found on this server. (bootstrap.min.css.map, line 0)
[Error] Failed to load resource: The requested URL was not found on this server. (bootstrap.bundle.min.js.map, line 0)
[Log] Error encountered: (cordova.js, line 1413)
– "Script error." – "↵ Url: " – "↵ Line: 0" – "↵ Column: 0"
[Error] TypeError: undefined is not an object (evaluating 'rssentries.length')
searchID (code.js:3270)
GetAirportInfo (code.js:1758)
(anonymous function) (code.js:1697)
After setting the variable rssentries I now get:
[Error] Failed to load resource: The requested URL was not found on this server. (bootstrap.min.css.map, line 0)
[Error] Failed to load resource: The requested URL was not found on this server. (bootstrap.bundle.min.js.map, line 0)
When the app first loads I get this… the same thing you said to ignore… just letting you know the sequence…
And nothing in the console.log
[Error] Failed to load resource: The requested URL was not found on this server. (bootstrap.min.css.map, line 0)
[Error] Failed to load resource: The requested URL was not found on this server. (bootstrap.bundle.min.js.map, line 0)
then as soon as I search for an airport I get:
[Error] Failed to load resource: The requested URL was not found on this server. (bootstrap.min.css.map, line 0)
[Error] Failed to load resource: The requested URL was not found on this server. (bootstrap.bundle.min.js.map, line 0)
[Error] TypeError: undefined is not an object (evaluating 'rssentries.length')
searchID (code.js:3269)
GetAirportInfo (code.js:1758)
(anonymous function) (code.js:1697)
Here is where I call my database: my app calls loadDB() and it calls ajaxRequest
// *********************
// load database
// *********************
function ajaxRequest(){
var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
for (var i=0; i<activexmodes.length; i++){
try{
return new ActiveXObject(activexmodes[i]);
}
catch(e){
alert("error");
//suppress error
}
}
} else if (window.XMLHttpRequest) // if Mozilla, Safari etc
{ return new XMLHttpRequest();
}else{
return false;
}
}
function loadDB(){
var mygetrequest = new ajaxRequest()
mygetrequest.onreadystatechange=function(){
if (mygetrequest.readyState==4){
alert(mygetrequest.status);
if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1){
jsondata = eval("("+mygetrequest.responseText+")"); //retrieve result as a JavaScript object
// NSB.MsgBox(JSON.stringify(jsondata));
rssentries = jsondata.items;
// NSB.MsgBox('Loaded <'+rssentries.length+'> airports!');
} else {
NSB.MsgBox("Database not loaded. Report error to developer.");
}
}
}
mygetrequest.open("GET", "airports2.json", true);
mygetrequest.send(null);
}
I put an alert status in the loadDB and it returns 200 when running in desktop browser, but when I deploy it to my iPhone it yields 0. So I don’t think any db is getting loaded.
To answer your question …why rssentries is not an object? I assume when rssentries = jsondata.items; occurs in loadDB… This above me. I just copied this code when I was writing my app 10 years ago using Mobione !!!