[TIMOB-14231] iOS7: Can't read a file from the Resources folder
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-07-17T20:53:07.000+0000 |
Affected Version/s | n/a |
Fix Version/s | 2013 Sprint 15 API, 2013 Sprint 15, Release 3.1.2, Release 3.2.0 |
Components | iOS |
Labels | filesystem, ios7, qe-closed-3.1.2, qe-testadded |
Reporter | Marcus Olovsson |
Assignee | Ingo Muschenetz |
Created | 2013-06-13T19:16:53.000+0000 |
Updated | 2015-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"
}
]
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.
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:
That's an identical path to what I was seeing. Try again, it's possible you didn't apply the change properly.
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!
Moved issue to Ti-Mobile, linked to new iOS7 support page. Request to implement pull request from Dawson for the fix.
To QE: Please add contacts to your device or simulator before testing . Test code: app.js
meow.json
Tested and verified fix with: Appcelerator Studio, build: 3.1.2.201307261628 Xcode5-DP4 iPhone5 iOS7 iPad 4 iOS7