Hi,
I have an app with iap integrated. The iap allows the user to upgrade the app to the full version (so it is a one time purchase).
When the user ‘buys’ the iap upgrade, the app creates and saves a file on the phone indicating that the upgrade had been purchased. That way, upon app start up, the app checks the file to see whether it should ‘unlock’ the full content. So from a buyer’s point of view, every time they run the app, it should be the full version.
However, sometimes, when the buyer starts the app, they get the ‘lite’ version instead of the full content despite having run the app with ‘full’ content multiple times before. This happened with more than one user. It also happened multiple times with two of them. Usually, when this happens i ask the users to ‘tap’ the dedicated ‘restore purchase’ button to resolve the issue, which it does.
My analysis is that it seems that sometimes the app can’t locate, open or read the file and hence will revert to the ‘lite’ version. But my question is why does it work most of the times and fails to do so sometimes for the same user on the same device?
Here is my code for saving the file after successful purchase:
saveStateToFile = function() -- write isFullVersion to file -- will write 'true' or 'false' local path = system.pathForFile("purchase", system.DocumentsDirectory) local file = io.open( path, "w") file:write( tostring(\_g.isFullVersion) ) io.close( file ) file = nil end
Here is my code for reading the file upon app start up:
loadPurchaseSettings = function() -- load purchased settings local file local str local path path = system.pathForFile( "purchase", system.DocumentsDirectory) file = io.open( path, "r") if file then str = file:read( "\*l" ) if str ~= nil then if str == "true" then \_g.isFullVersion = true else \_g.isFullVersion = false end else \_g.isFullVersion = false end io.close( file ) end end
(Note: if the upgrade has never been bought before, then no file should exist. The file will only exist after a ‘purchase’ has been initiated regardless of the purchase outcome.)
Any ideas on how to resolve this? Any insights?
Thanks
Luay