Here is the deal, I have an application in which the device listens to iBeacons in the background and timestamps the moment user passes the area in range. Initially, as soon as I get a didEnter call back I used the chance to save the information to the iCloud using CloudKit. But sometimes on a bad luck, the internet is not available at that very moment and saving fails (e.g. when the user is in elevator).
I tried to use FMDB to write the information to database and sync them when app enters foreground. That doesn't work either. Since iOS8 by default encrypts the disk and does not allow me to write to disk after the phone gets locked by the user or the phone get a reboot (eventhough there are some APIs in NSFileManager to let you write to a file until it's open called "NSFileProtectionCompleteUnlessOpen" but they don't work after few hours of phone being locked. Perhaps a bug).
Third solution was to write them into a array and use reachability to sync them to iCloud as soon as I get a chance (on location callbacks, appdelegate callbacks or reachbilityChanges notification). But this solution is not secure to app termination. If the user termiate the app I dont have enough time to do anything.
The last solution is a mix of all together. Write to array if the disk is encrypted. write to disk if not encrypted. sync them all together and save to internet at any time possible. Do not want to put myself in alot of hassles before getting some help.
Do you have any idea how to deal with this?