Hello everyone. I use a sample design in my login function:
local jsonFile = function( filename, base )
print (filename)
if not base then base = system.ResourceDirectory end
local path = system.pathForFile( filename, base )
local contents
local file = io.open( path, “r” )
if file then
contents = file:read( “*a” ) – read all contents of file into a string
io.close( file ) – close the file after using it
end
return contents
end
function networkListenerLogin( event )
if ( event.isError ) then
print( “Network error!”)
else print ( “RESPONSE” )
estatus = event.status
online = true
if estatus == 200 then
t = json.decode( event.response )
for key in pairs(t) do
print (key,t[key])
end
end
end
end
function getLogin()
params.body = “username=”…cnf_user…"&password="…cnf_pass
json_file_by_get = jsonFile( network.request( "https://api.myweb.com/v1/login",
“POST”, networkListenerLogin,params ) )
end
In simulator is everything OK, but during a test on phone (I tried 2 different phones) is reported
error “bad argument #1 to ''open” (string expected, got nil)" and filename in local jsonFile is “false”.
In build_setting i have
“android.permission.INTERNET”,
“android.permission.WRITE_EXTERNAL_STORAGE”,
“android.permission.ACCESS_NETWORK_STATE”,
“android.permission.ACCESS_WIFI_STATE”
I do not know what is wrong.
Thanks for some advice…