How to save data temporarily on iPhone? - iphone

I want to save some images from my server to the iPhone app temporarily.
It is one of my application's purposes to, when the user closes the app, delete the saved images.
Again, when the user starts my application and taps on the corresponding button again, I need to save the data. I don't know how to start it, I know only we can do this with the help of NSFileManager.
Please can anyone guide me on how to start or write the code.. Thanks in Advance :)

Store the files in either the tmp or Library/Caches folder. In neither case will the files be automatically deleted, but they won't be backed up and so don't contribute permanently to the app's storage requirements. If you also want to delete the files on close, do it in -applicationWillTerminate.

Related

Save PDF file to a user-defined default directory in iCloud Drive

I'm asking this question because I did not find any answer, and I'm starting to believe that it's not possible, due to security reasons. But who knows?
In my app, I simply let the user save a PDF file using UIActivityViewController. The user then chooses Save to file, then selects iCloud Drive.
Now, users ask me to be able to select a default location once and for all.
Is it possible? This location would of course be outside the app container, then I suppose iOS won't grant access unless the user selected it itself.
Yes you can. Using UIDocumentPickerViewController you can ask for a directory, and you can save it in your app. This is explained in detail in Providing Access to Directories. iOS 13 and later.
See also What's New in File Management and Quick Look for sample code saving a directory URL and then reusing it to set the base directory for a subsequent call to UIDocumentPickerViewController

iphone video upload in queue

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".

iCloud - Moving the file completed

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

Shipping Documents Items with an iPhone App

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.

Database + Sync (Iphone app)

How can I flush my sqlite database in my application when I click on a button?
I already have a database inside my app, when I click on a button it add some data into it.
I wanna know how to fluch the database after I click the button or maybe restart the application automatically.
Thanks,
Ok I find what I was looking for.
Don't really need to flush the database, the only things I had to do is to copy my database from the bundle to the document directory, because the database in the bundle is Read only.
Make a Copy of it allow to Write/Read access.
Add/Delete/Update data can be executed without problem after that.