Uploading file to icloud-documents even if the memory is full it doesn't give any error - cloudkit

I use iCloud documents to sync file between device. it works correctly but the main issue is, when iCloud exceed to 5 GB which is maximum allowed for free account, so in this case when I upload the file it continue to write in FileManager but I can not see in another device this because the memory of iCloud is full. But it doesnt give any error feedback using write(to:) method. so my question is how to know if iCloud storage is full in order to show error to the user?
so

Related

iCloud Drive take forever to upload. Is there a way to rush "Waiting to upload state"?

I have two 50KB files saved in iCloud Drive. Using FileManager, saved in an iCloud container.
The problem is that they take forever to upload. I waited 2 hours and they are still in this waiting to upload status. Both my iPhone and iPad having this issue.
Is there a way I can force it upload? Or at least put it into priority queue.
I'm building a note app sync feature. And those slow upload makes sync impossible.
I ran into a problem like yours and tried to find the solution. So, I contacted directly to Apple Support.
Here's the suggestion:
First, you have to make sure that your OS version is up to date and your iCloud storage has enough space.
Next, you go to System Preference > Apple ID > uncheck a checkbox in front of iCloud then check it back.

Delete local iCloud Data on Device (e.g. at first app launch/reinstallation)

If a user installs an an app which uses iCloud with a UI(Managed)Document, then uses the app, creates data which is saved to iCloud and then deletes the app on his phone, the iCloud data will stay on the device (transaction logs etc.). If the user reinstalls the app it will try to use these old files.
I have the following two problems with that:
The iCloud documents could have changed in the meanwhile and there might be problems when the user has no network connection on the first launch after reinstalling the app.
The iCloud documents for this app could have been deleted by the user (via settings or in Mac OS Finder in the user library). Now, when the user has no network on the first launch after reinstalling the app, the app might think that there is an ubiquity container with data even though it's already deleted (app might crash).
This is not very easy to test but I have definetely crashes and malfunctions for those two issues. E.g. NSMetadataQuery shows me results for documents which do not exist in iCloud because they have been deleted (but they existed on the deletion of the app).
Is there any easy solution to this? I thought about deleting the local iCloud data on the device when the app is launched for the first time - but how can this be done?
It can't be done. If you delete an iCloud document locally, you delete it everywhere-- eventually. The iCloud APIs have no concept of managing local copies independently of the iCloud service, so if you delete one-- even with the network down-- the iCloud ubiquity daemon will send a delete command to the service at the first opportunity.
The closest approximation that current APIs would allow would be:
Check whether the network is reachable
If it's not reachable, do not attempt to access any iCloud documents (because as you note, the information might be stale).
If and when the network comes up, try to open all existing iCloud documents. (On iOS, iCloud updates are only downloaded on demand, so you need to create that demand).
If that's not good enough (and let's face it, it's not good enough), file a bug with Apple and hope for the best.

how many images can I cache in my iPhone app?

I'm wondering how many images I can store in the iPhone documents directory so that I don't get any memory issues. I'm torn between caching images or loading them from a webserver every time the user wants to access them. There most likely won't be more than 10-20 images cached at any given time...
Any thoughts?
There's a 2GB cap on the largest size of a single file in the /Documents folder. Other than that, you can store as many images as you want. iOS itself didn't put a limitation on how much space you can use on a device. So your space limit is the size of Flash on the device (i.e. 16GB, 32GB etc).
You might consider use the /Library/Caches instead because iCloud will attempt to sync the Documents folder (if entitlements are configured). I heard App being rejected by review for excessive use of the Documents folder. To get the path, call NSSearchPathForDirectoriesInDomains with NSCachesDirectory and NSUserDomainMask.
Though a user can determine the size of space you are occupying in System Settings.
You can probably cache as many files as available memory allows, but you absolutely should be safe having 10 - 20 images cached at any given time.
B.T.W., instead of using the documents directory, why not consider using the cache directory as He (+1 to him!) suggests?
Here is a related question that shows how to get the size of the directory.

how can i do Limit the file app size in ipad?

I want to write a app to download and manage files from the web. If I just put the file in the Document. Is there any limit of file size in the Directory?
can any one help me..
thanks in advance.
Just a warning with the introduction of iOS5 saving large files or files that can be regenerated into the documents directory is frowned upon (actually you were never meant to do it but its only being enforced now). This is because the files in the documents directory get backed up to iCloud and you obviously do not want to fill that up. Apple have started rejecting apps just for this reason.
You should now place the downloaded files into the temp or cache directories. But also be aware that the OS will clear these directories when running low on memory so you need to have logic in you app to check if the files exist and re-download if they do not.
No real limit except the device and other user data. Still best to be frugal.

Does the iPhone / iPod touch cache data also on disk, or only in memory?

I am not sure, but I think I was reading a while ago that iPhone / iPod Touch don't cache anything to disk. They cache only in memory. So cache is not persistet when app quits. After relaunch of app it will re-fetch the data from the net. Is that true?
iPhone OS disables on-disk caching from NSURLCache on this platform. If you need on-disk caching support anyway, you can use http://github.com/rs/SDURLCache which gives back on-disk cache support on iPhone OS
You can explore this yourself using the iPhone Simulator, opening a terminal or using the Finder, and going to `~Library/Application Support/iPhone Simulator/User/Applications/ then opening whatever directory your application is in.
You'll see a Documents directory, a Library and a tmp directory.
I've never looked to see if UIWebView is caching anything, but I know that Core Data will.
If you just suck down data yourself using CFNetwork, I believe it's up to you to cache the data yourself by saving it to tmp or Documents if you want.
tmp will not get backed up by the iTunes Sync process, but Documents will, so don't use Documents for temporary cache. Otherwise you'll just waste space and slow down sync backups.
The Documents directory will persist through anything, including app upgrades, except outright deleting the application using the Springboard or doing a total device storage wipe.
Actually the Library directory has directories. called Cache, WebKit/LocalStorage, and Preferences. So that would suggest something or the other.
Don't write to the application bundle directory or bad things could happen.
iPhone apps can write data to disk.