Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14231] iOS7: Can't read a file from the Resources folder

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-07-17T20:53:07.000+0000
Affected Version/sn/a
Fix Version/s2013 Sprint 15 API, 2013 Sprint 15, Release 3.1.2, Release 3.2.0
ComponentsiOS
Labelsfilesystem, ios7, qe-closed-3.1.2, qe-testadded
ReporterMarcus Olovsson
AssigneeIngo Muschenetz
Created2013-06-13T19:16:53.000+0000
Updated2015-06-12T15:55:13.000+0000

Description

*Problem* I often have JSON-files with configuration for my app. I noticed in iOS 7 that my apps won't even start, because it won't read my JSON-files. It seems like it can't find anything in the Resources-directory (I haven't tried other directories yet). *Test-case* 1. Create a project with the files below 2. Ignore my variable names 3. Run the app, click on the button *Expected result* It should print a bunch of names in the console. *Actual result* I get the "meow.json is missing" error. *app.js*
Titanium.UI.setBackgroundColor('#000');

var win = Ti.UI.createWindow({
  backgroundColor: "#fff"
});

var button = Ti.UI.createButton({
  title: "INSTALL CATS",
  height: '50dp',
  width: '140dp'
});

win.add(button);

win.open();

button.addEventListener('click', function() {

  var allTheCats = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'meow.json');

  if (!allTheCats.exists()) {

    Ti.API.error("meow.json is missing");

  } else {

    allTheCats = JSON.parse(allTheCats.read().text);

    allTheCats.forEach(function(cat) {

      var test = Ti.Contacts.getPeopleWithName(cat.firstName);
      Ti.API.info(JSON.stringify(test));

    });

  }

});
*meow.json*
[
  {
    "firstName": "Reno"
  },
  {
    "firstName": "Sonny"
  },
  {
    "firstName": "Vincent"
  }
]

Comments

  1. Dawson Toth 2013-06-14

    Maybe fixed with this PR -- https://github.com/appcelerator/titanium_mobile/pull/4393 -- I was seeing something very similar. You might give it a go and see if it works for you too, Marcus.
  2. Marcus Olovsson 2013-06-14

    Dawson Toth: Tried adding your fix but sadly it didn't seem to help. I added .getNativePath() and .resolve() to see which paths it is using, if that helps:
    [ERROR] file:///Users/arood/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/5F7E931D-94E1-4733-BC6C-86B9801EA0C8/Katter.app/file:/Users/arood/Library/Application%2520Support/iPhone%2520Simulator/7.0/Applications/5F7E931D-94E1-4733-BC6C-86B9801EA0C8/Katter.app/meow.json
       [ERROR] /Users/arood/Library/Application Support/iPhone Simulator/7.0/Applications/5F7E931D-94E1-4733-BC6C-86B9801EA0C8/Katter.app/file:/Users/arood/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/5F7E931D-94E1-4733-BC6C-86B9801EA0C8/Katter.app/meow.json
  3. Dawson Toth 2013-06-14

    That's an identical path to what I was seeing. Try again, it's possible you didn't apply the change properly.
  4. Marcus Olovsson 2013-06-14

    Ah yes, thought it would be enough to change the class-files in the build-folder. Tried applying it to the SDK-folder itself and that seems to have worked! Thanks!
  5. Carter Lathrop 2013-06-14

    Moved issue to Ti-Mobile, linked to new iOS7 support page. Request to implement pull request from Dawson for the fix.
  6. Olga Romero 2013-07-30

    To QE: Please add contacts to your device or simulator before testing . Test code: app.js
       Titanium.UI.setBackgroundColor('#000');
        
       var win = Ti.UI.createWindow({
         backgroundColor: "#fff"
       });
        
       var button = Ti.UI.createButton({
         title: "INSTALL CATS",
         height: '50dp',
         width: '140dp'
       });
        
       win.add(button);
        
       win.open();
       
       button.addEventListener('click', function() {
       	if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_AUTHORIZED){
       		performAddressBookFunction();
       	} else if (Ti.Contacts.contactsAuthorization == Ti.Contacts.AUTHORIZATION_UNKNOWN){
       	    Ti.Contacts.requestAuthorization(function(e){
       	        if (e.success) {
       	            performAddressBookFunction();
       	        } else {
       	            addressBookDisallowed();
       	        }
       	    });
       	} else {
       	    addressBookDisallowed();
       	}
       	
       });
       
       function performAddressBookFunction() {
         var allTheCats = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'meow.json');
        
         if (!allTheCats.exists()) {
        
           Ti.API.error("meow.json is missing");
        
         } else {
        
           allTheCats = JSON.parse(allTheCats.read().text);
        	
        	allTheCats.forEach(function(cat) {
       	Ti.API.info("A cat is named: "+cat.firstName);
       	
             var test = Ti.Contacts.getPeopleWithName(cat.firstName);
            
           });
        
         };
       };
       
       function addressBookDisallowed() {
       	alert("You are not allowed to access contacts");
       };
       
       
    meow.json
       [
         {
           "firstName": "Reno"
         },
         {
           "firstName": "Sonny"
         },
         {
           "firstName": "Vincent"
         }
       ]
       
    Tested and verified fix with: Appcelerator Studio, build: 3.1.2.201307261628 Xcode5-DP4 iPhone5 iOS7 iPad 4 iOS7

JSON Source