How to include a database file with my IOS build

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?

Paul

It probably is being transferred with your app - but CORS security isn’t allowing your app to access the file.

To test this, do Remote Debugging to see what errors are appearing on the Console.

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?

Paul

Good - you’re making progress.

What does the statement you use to access airport2.json look like?

Thanks George, here it is:

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()

I may be confused. Are you having the problem while running on your iOS device or on your local server?

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.

The solution may be different in a local server than in a native app.

Is it only the native app you are interested in?

If so, when you run as a native app, are there any message in the Remote Console?

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)

Still does not access the database.

You can ignore the bootstrap files not found messages - they do not affect anything.

Good job getting the Remote Console working. Now you can use some console.log() statements to trace what is happening with your app during execution.

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)

and this in the console.log:

[Log] Error encountered: (cordova.js, line 1413)
– “Script error.” – "↵ Url: " – “↵ Line: 0” – “↵ Column: 0”

So, trace back why rssentries is not an object. What’s in it? How does it get set?

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 !!!

the database is a json type and looks like:

{
items: [
{
  Ident: 'EKYT',
  City: 'Aalborg',
  State: 'Denmark',
  Lat: 'N57-05.6',
  Long: 'E009-51.0',
  Std: '1',
  Day: '2',
  Zone: 'E',
},
{
  Ident: 'BOS',
  City: 'Boston (Logan Intl)',
  State: 'MA',
  Lat: 'N42-21.9',
  Long: 'W071-00.3',
  Std: '-5',
  Day: '-4',
  Zone: 'NA',
}
]
}

Hopefully you can help here.

Time to do more tracing, I guess. Have a careful look at everything which is returned by your ajaxRequest() function.