I have been troubleshooting an issue where the majority of the time I do not get a remoteRegistration event (thus no token) during a fresh install of my app. However, I can clear the app’s data, fire up the app and get a token every single time.
I have tried both 2016.2992 and 2017.3068 using v1 and v2 of the notifications plugin on both. It doesn’t matter if I use GCM or FCM, the result is the same; no token after a fresh uninstall/reinstall but a token every time if I clear data (although 2992 with GCM received the token more often than not.)
That made no sense to me. It was almost as if I had some sort of residual data in the system.DocumentsDirectory still on my phone even after an uninstall. So I decided to add the following readily-available code to the top of my main.lua and sure enough, after a uninstall/reinstall there are game files located in the documents directory that should only be there once the user signs in and starts playing the game!
local lfs = require( "lfs" ) local doc\_path = system.pathForFile( "", system.DocumentsDirectory ) for file in lfs.dir( doc\_path ) do -- File is the current file or directory name print( "Found file: " .. file ) end
My research led me to these two articles:
The first article was spot on. I turned off “Automatic Restore” on my phone (3 different phones really) and now I get a token every time after I do an uninstall/install. “Automatic Restore” was restoring old games files into the system.DocumentsDirectory which made my app not “request” a new token (or so it seems that way to me.) Some of these game files were three months old!
So my question, is there a way we can turn off “Automatic Restore” for our app as discussed in the two posts above? Not only was this a problem with getting a remoteRegistration event, I can see it being an issue with game files as well.
Thanks ahead of time!
Scott