I want to put all my app logs in a file in the Documents directory and then once user tap on "Upload logs" in the application, logs will be uploaded to server. I am planning to keep logs for two days. Is there any limit on the size which I can use for the logs?
Also, at all point in time I want to keep last 2 days logs and deleting the old ones. How can that be achieved?
Since you are storing them in the Documents directory, you are not bounded to a specific file size. As for only keeping the last two day's log files, you could just write a pruning function to delete any old ones and call it on app launch & resume from background.
Related
My iPhone app was rejected last week because of me not following iOS Data Storage Guidelines. My app basically searches for certain data and shows them to the user who can share them with others (Twitter, Email, etc) or save them to "Favorites" to view them later.
Earlier:
Earlier, I didn't follow any particular data strategy. My app was basically downloading all search data (images) into /Documents/ directory. Once the user marked a particular item as a "Favorite", those were saved into my custom made "Favorites" directory in /Documents/ path. My app doesn't use iCloud. Besides, I also forgot to purge downloaded search data (images) once the user has seen them and is no longer in the same view. I have since found out that the entire strategy was terrible and the reason for my app's rejection.
Now:
Now, since my app has been rejected, I have doubled down on fixing my app and making it as perfect as possible. The data strategy that I am following is very simple now:
a) All the downloaded search data (images and pList files for search results) are now created in /Library/Caches directory.
b) When the user adds an item to "Favorites", data associated with that item (image and text) are then saved into /Documents/ directory.
c) All the files in /Library/Caches and /Documents/ directories are marked with the attributed "Do not backup", since I don't want to take any space on iCloud.
d) All the search related data in /Library/Caches directory are immediately purged once the user moves to a different view and is not longer accessing the search results.
e) On app launch, I check to see if there are any residual files from previous session in /Library/Caches directory in case the app got terminated prematurely. If any residual files from previous search session are found, I delete them.
My question are:
A) Is the data storage strategy that I am following now acceptable?
B) Do I need to mark any search related files in /Library/caches/ with "Do not backup" attribute or is that unnecessary?
C) Should I mark the data related to user's favorite items in /Documents/ directory with "do not backup" attribute or is it okay if user's favorite items get backed up to iCloud?
A) This data strategy sounds much better with maybe one minor adjustment listed below.
B) You do not need to mark these files with the "Do not backup" attribute. Also, you do not even need to manually purge these files. These files are not backed up through iTunes or iCloud, and will only be cleared in certain extreme cases of low disk space.
C) The user's favorite items should certainly be backed up to iCloud. This would be a proper use of iCloud since it is intentionally for user generated content.
Here is a situation I have a data file in document directory which is being updated in the application every now and then. So I want to save it to my desktop using iTunes. But I don't want that the file should be uploaded back to my application. i.e. I want that user can download the file but can not upload any.
I was thinking to have the data file on some other location like Library and put a button on application settings saying "Prepare backup" that will copy that data file in Document directory, from where user can download it. If user uploads any thing it won't make any difference as my current file is in Library directory.
This is just a thought,
can anyone suggest me other way or the above way is good to go?
Edit: I just need that after the successful export user can view the data file (may be later) without support of the application.
You can't.
But what you can do is check (using an timer every 10 seconds) if a new file is added to the documents directory and then delete it programmatically.
But this ofcourse doesn't disable the replacement of files.
I need to record video and upload them to Server. They will be added in queue and uploaded one by one.
My question is, when i record a video, where should i save it till it gets uploaded ?
Should i save it in Album ? or in private documents directory ?
I also need to delete the video once it is uploaded.
According to ios guidelines, is it required to save the video in Albums only ? Will my app be rejected if it is saved in Documents directory for longer period?
If they are not user-created (or if you do not want them to participate in stuff like iCloud), then do not put them in APPHOME/Documents.
The preferred location is APPHOME/Library/Caches but that location can get cleaned by the iOS on a system restore (and possibly other times -- documentation does not specify). It's not going to happen on a regular basis though, so it's the first option if you can regenerate the data on rare occasions like restore.
So, if the files can be recreated, keep them in APPHOME/Library/Caches. If they cannot, then place them somewhere else in APPHOME/Library.
Just make sure you remove them when you are done with the upload.
You're ok, you can save/delete them in/from the Documents directory. Instead, you can't delete videos/photos from the user's albums. No problem for the "longer period".
I can able to move a file from the local directory to iCloud using the condition setUbiquitous:YES. The file has been moved successfully. If the file size is large, it takes certain time to complete moving. Is there any method to identify, if the file has completed moving to iCloud? Thanks in advance for your answers.
Note: I haven't done this myself, so all the info below is purely from reading the documentation:
The NSMetadataItem class has, among others, an attribute key called NSMetadataUbiquitousItemIsUploadedKey. Knowing this, you should be able to set up an NSMetadataQuery that notifies you once the item has been uploaded.
You can check with NSUURL getResourceValue:forKey:error: method
NSURLUbiquitousItemIsUploadedKey—Indicates that locally made changes were successfully uploaded to the iCloud server.
NSURLUbiquitousItemIsUploadingKey—Indicates that locally made changes are being uploaded to the iCloud server now.
NSURLUbiquitousItemPercentUploadedKey—For an item being uploaded, indicates what percentage of the changes have already been uploaded to the server.
For details: https://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/iCloud/iCloud.html#//apple_ref/doc/uid/TP40007072-CH5-SW1
My iPhone app uses a small database to store its settings and saved files. How can I ensure that the default database, with its default settings, gets distributed to anyone who downloads it along with the application files?
EDIT Sorry, I was in a rush when I posted this. I forgot to mention that the database needs to end up in the 'Documents' folder of the application so that it can be backed up at a later date by the user.
-Ash
Put it in "Resources". Then on your first launch, you'll need to load that file out of your mainBundle and save it to the Documents directory. The file will "come with" the app, but it won't live in the right place to get caught by backup.
A side-effect is that restoring the app to factory settings is as easy as deleting that file. Next launch, you can see you don't have your file, and copy a fresh one out of your bundle.
You include it as a file in the Resources folder of your application.