box.com save token works in sim but not device

I am successfully in commo with box.com on the simulator - i auth, get a token and save the json to the DocDir and retrieve and use at will.  UNTIL i get to the XCode simulator or the ios device; then it wont save the token json file.  Ive tried DocDir and CacheDir and both work fine in the simulator but not devices…stumped and need a hand debugging please.

I read a thread where it sounds the same and Rob Miracle was kind to 

App  works  fine in  simulator , only black screen on device 

25 posts

Nov 22, 2013

Saving Files  works  in  Simulator but not  Device! -  iOS  …
 

point out a link to a forum on debugging:

http://www.coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

but it no longer links… anyone have a clue?

wkr,

-sean

Debugging Guide found here now:

thanks roaminggamer.  Unfortunately i have gotten that far but am not getting much out of the basics to help with this issue…

I have been able to write a directory called, “db” and an sqlite3 file called, “WatchData.sqlite3” successfully to both folders.  Interestingly this was not working when the file name suffix was “sqlite”… leading me to believe I may have an issue with file naming.  I am trying to write a file named, “AuthToken.json” and have also tried “AuthToken.txt”.  Both work in the simulator but not the device or xcode sim.  :(

I also do know the commo is working as it goes out to box and presents the auth dialog and app confirm dialog on both sim and device but on the device never saves a token - nor does it log an error on the device… sort of a nothing happens.

Can you provide some code where you’re trying to get this data?

Rob

read:

    local file = io.open(system.pathForFile(“boxAccount.txt”, system.CachesDirectory), “r”)

– First, check if it’s a saved refresh token, so we can authenticate user without prompting him to enter login and password

    if file then

        local googleAccount = json.decode(file:read( “*a” ))

        io.close( file )

        requestToken(googleAccount[“refreshToken”])

      print( "we have an active token json file… " )

      table.insert( g.VerifiedPaths, “we have an active token json file…  shouldnt restart auth process” )

    else

      – If we don’t have a refresh token, open a webPopup so he can log in

    print(“starting authenticate”)

    authenticateUser() 

    end

– the above, which on the device always fails and goes to re -authenticate.  works fine on corona sim, not xcode sim

write:

– Saves the user’s refresh token on a json file

function saveRefreshToken()

    local file = io.open(system.pathForFile(“boxAccount.txt”, system.CachesDirectory), “w”)

    if file then

        file:write( json.encode({refreshToken = credentials[“refresh_token”]}) )

        io.close( file )

    end

end

I think the culprit is in the redirect url and ATS:

options.redirect_uri = “http://localhost:9004”  – no likey

any thoughts on an acceptable redirect to local host that ATS will choke down?

I was hoping to see your networking code because it sounded like an ATS issue. I don’t know what this redirect URL is, but you likely will have to add an ATS exception in build.settings for localhost.

Rob

i tried that via the plist and afterwards xcode gripes about the signature not being right.  How do I do that in the buld settings please?

thanks for the help rob!

https://docs.coronalabs.com/guide/hardware/appleATS/index.html

Boooooooya!  Thanks Rob!  Classic misplaced problem - solved via community!  Thanks all!

Debugging Guide found here now:

thanks roaminggamer.  Unfortunately i have gotten that far but am not getting much out of the basics to help with this issue…

I have been able to write a directory called, “db” and an sqlite3 file called, “WatchData.sqlite3” successfully to both folders.  Interestingly this was not working when the file name suffix was “sqlite”… leading me to believe I may have an issue with file naming.  I am trying to write a file named, “AuthToken.json” and have also tried “AuthToken.txt”.  Both work in the simulator but not the device or xcode sim.  :(

I also do know the commo is working as it goes out to box and presents the auth dialog and app confirm dialog on both sim and device but on the device never saves a token - nor does it log an error on the device… sort of a nothing happens.

Can you provide some code where you’re trying to get this data?

Rob

read:

    local file = io.open(system.pathForFile(“boxAccount.txt”, system.CachesDirectory), “r”)

– First, check if it’s a saved refresh token, so we can authenticate user without prompting him to enter login and password

    if file then

        local googleAccount = json.decode(file:read( “*a” ))

        io.close( file )

        requestToken(googleAccount[“refreshToken”])

      print( "we have an active token json file… " )

      table.insert( g.VerifiedPaths, “we have an active token json file…  shouldnt restart auth process” )

    else

      – If we don’t have a refresh token, open a webPopup so he can log in

    print(“starting authenticate”)

    authenticateUser() 

    end

– the above, which on the device always fails and goes to re -authenticate.  works fine on corona sim, not xcode sim

write:

– Saves the user’s refresh token on a json file

function saveRefreshToken()

    local file = io.open(system.pathForFile(“boxAccount.txt”, system.CachesDirectory), “w”)

    if file then

        file:write( json.encode({refreshToken = credentials[“refresh_token”]}) )

        io.close( file )

    end

end

I think the culprit is in the redirect url and ATS:

options.redirect_uri = “http://localhost:9004”  – no likey

any thoughts on an acceptable redirect to local host that ATS will choke down?

I was hoping to see your networking code because it sounded like an ATS issue. I don’t know what this redirect URL is, but you likely will have to add an ATS exception in build.settings for localhost.

Rob

i tried that via the plist and afterwards xcode gripes about the signature not being right.  How do I do that in the buld settings please?

thanks for the help rob!

https://docs.coronalabs.com/guide/hardware/appleATS/index.html