Bug read file ios browser in html5

Hi,

I try to read file .json in html5 change value save it and reload browser, it work fine in PC browser and android browser all value saved and loaded fine but in ios browser it not saved.

try code below

local json = require( "json" ); local database = { } local path = system.pathForFile( "test.json", system.DocumentsDirectory ); local function save( contents ) local file = io.open( path, "w" ); if file then local contents = json.encode( contents ); file:write( contents ); io.close( file ); return true; else return false; end end local function load( ) local myTable = { } local file = io.open( path, "r" ) if file then -- read all contents of file into a string local contents = file:read( "\*a" ); myTable = json.decode( contents ); io.close( file ); return myTable; end end local file = io.open( path, "r" ); if file == nil then print( "create file" ) local contents = { }; contents.isBool = true; if( save( contents )) then local newContents = load( ); print( "Value isBool", newContents.isBool ) -- Change value to false timer.performWithDelay( 1000, function( ) newContents.isBool = false; print( "Change value isBool", newContents.isBool ) save( newContents ); end, 1 ); end else io.close( file ); print( "Load data", load( ).isBool ); end

You’re trying to run an HTML5 Corona app on and iOS device? 

Doesn’t that seem kind of round about?  Why not just make an iOS app with Corona.

Also, I kind of don’t think iOS is going to give you permission to do that (write a file) from an app in the browser.

I build my game to html5 and I saved my setting and unlock game level in json file. When i reload chrome browser in ios all setting and unlock game level dont saved.

My question was, why?  Why would you choose the build target as HTML5, but then run it on any mobile device?  That seems like it would be low performance way to distribute when you could specifically build an iOS app.

That said, if you simply want folks to be able to run your HTML5 game/app from any desktop or mobile device, then this is valid question.

Still, I wonder if iOS is not restricting your ability to write.  

Hopefully someone clever or knowledgeable of iOS settings will have some insight.

@roaminggamer, when you start build an HTML5 game your users could come from any location and like building a website, you have to test in all the browsers that a user could use. So it’s very possible someone could find your game in iOS Safari or an Android tablet with Chrome. The game needs to work there as well.

I don’t know much about running Chrome on iOS. I don’t know how well we’ve tested that combination as I think most iOS users are just going to use the built in Safari.

Rob

in safari browser dont work too.

You could be running into an issue similar to here:

https://forums.coronalabs.com/topic/73085-issue-with-loading-files-from-systemdocumentsdirectory-and-systemtemporarydirectory/

The next daily build should have a fix for the issue above. I would suggest checking it for your issue as well.

Rob

You’re trying to run an HTML5 Corona app on and iOS device? 

Doesn’t that seem kind of round about?  Why not just make an iOS app with Corona.

Also, I kind of don’t think iOS is going to give you permission to do that (write a file) from an app in the browser.

I build my game to html5 and I saved my setting and unlock game level in json file. When i reload chrome browser in ios all setting and unlock game level dont saved.

My question was, why?  Why would you choose the build target as HTML5, but then run it on any mobile device?  That seems like it would be low performance way to distribute when you could specifically build an iOS app.

That said, if you simply want folks to be able to run your HTML5 game/app from any desktop or mobile device, then this is valid question.

Still, I wonder if iOS is not restricting your ability to write.  

Hopefully someone clever or knowledgeable of iOS settings will have some insight.

@roaminggamer, when you start build an HTML5 game your users could come from any location and like building a website, you have to test in all the browsers that a user could use. So it’s very possible someone could find your game in iOS Safari or an Android tablet with Chrome. The game needs to work there as well.

I don’t know much about running Chrome on iOS. I don’t know how well we’ve tested that combination as I think most iOS users are just going to use the built in Safari.

Rob

in safari browser dont work too.

You could be running into an issue similar to here:

https://forums.coronalabs.com/topic/73085-issue-with-loading-files-from-systemdocumentsdirectory-and-systemtemporarydirectory/

The next daily build should have a fix for the issue above. I would suggest checking it for your issue as well.

Rob