Sometimes my Flutter application loses the internet connection when app is suspended for a long time. It mostly happens when the iPhone locks the screen automatically after inactivity. Then, when the iPhone is unlocked and the app resumed, every single request, either an API call or a firebase access, does not complete successfully.
I'm reproducing this using a real iPhone 7. Looking into my app Crashlytics, it seems it happens in a different way in newer iPhones (after iPhone 12). In these new devices, after the internet connection lost, every firebase database request throws a firebase-database/permission-denied
error. I've already talked to the Firebase Flutter support and they've confirmed it is a misinformation because it doesn't have anything really related to my databse rules.
Our best guess is that there's something wrong in my Flutter application set up that makes iPhone lose the connection to the internet after a long time suspended (which is the correct behavior), but it isn't able to retrieve this connection automatically (here's the problem).
I've already added UIBackgroundModes like this:
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>processing</string>
<string>remote-notification</string>
</array>