Valid file types for iCloud? - iphone

I find many similar question but i didn't get solution for this.
Is it possible to upload some file like image, document, zip file to upload on iCloud programmatically?

See table 4-1 in the documentation:
How do you manage the data? Manage files and directores using the
NSFileManager class. Open, close, read, and write files using standard
file system routines.
So if you can create a file, you can store it in iCloud. But remember there's a finite, relatively small amount of space available.

iCloud can handle all kinds of files. So if you want rot use an obscure file format or invent your own, go for it. It only can to be converted into a byte stream/NSData, but then again, what isn't?
Check this tutorial walkthrough app. It shows how to create, modify and delete files for iCloud.
http://github.com/lichtschlag/iCloudPlayground

Related

How to manage the iCloud Document of MAC App

The documents provided by APPLE did not make it clear to me. This may be my English level limit. I hope you can help me to get a better understanding of it.
I use the FileManager class to manage the files of icloud, including the methods of copyItem, moveItem, and removeItem. I directly deal with the files in the icloudDocument's address as an ordinary file. After matching with NSMetadataQuery, I compare the modification time and creation time of files, so I managed files, but I found it very bad, because I need to judge whether files need updating, uploading or deleting.
I later found that the FileManager class has Managing iCloud-Based Items, which includes the evictUbiquitousItem, startDownloadingUbiquitousItem, and other methods. It seems to be easy to manage, but it doesn't make me clear.
My problems are now:
which is the final file when the local file is not consistent with the icloud file? (there is no convenient method, automatic synchronization)
what should I do if the icloud does not exist, but when the local file exists? (delete it directly? Or is it necessary to judge?)
how do you know which files are downloaded to the local?

Is iCloud only meant for UIDocument and CoreData(How to Take Back up of any folder with its data on iCloud)

I read the apple documentation and some other links and found there are examples of using iCloud with only either UIDocument or Core Data.
I am having a folder created in documents directory named "backUPFolder" and it contains some images and other files in it.
I want to ask , if it is possible to move this backUPFolder in iCloud with all the data exist in this folder as it is.
If yes it is possible please provide me some useful link or suggest an approach which I can follow.
My requirement is to take a back up of my data on iCloud.
Please please help me.
I am stuck here.
Any suggestions would be highly appreciated.
Thanks in advance!
I have also only seen the UIDocument and Core Data examples. What comes to mind is to transform your pics and docs into Core Data blobs and store them with core data anyway. This could also be very efficient.
Alternatively, you could check out the Dropbox APIs.
If your folder in the Documents or Library folder of your application, it will be backed up to iCloud automatically assuming the user has iCloud enabled (and that you haven't explicitly flagged the file as NSURLIsExcludedFromBackupKey).
Any manual interaction with iCloud as a developer is typically to share files explicitly between installations of your app. If your requirement is just to back up data, you don't need to do anything besides store the folder in Documents.

Download and unpack a *.tgz file to a subdirectory of the Documents directory

There very well may be an answer to this already on SO, but I'm not familiar enough with compression formats to know if they're applicable to my case. So here's what I need:
1) Download a *.tgz file that is greater than 200MB.
2) Unpack it to a specified subdirectory of the Documents folder.
I know how to make the connection and begin downloading. But how do I download to an actual file (rather than storing it in memory), and once this download is complete how do I unpack it to my desired location?
To save the downloaded data to a file, see this SO-question and answer(s): The easiest way to write NSData to a file
To uncompress .tgz-files, see this question and answer(s): "Untar" file on iPhone
To download large files, see this question and answer(s): How to download large files using objective c on iphone
(Google is an awesome tool, really.)
Just as a sidenote, an app shouldn't download 200MB of data. It is time- and bandwith consuming and may cause Apple to reject your app.
Forget NSURLConnection; use ASIHTTPConnection (google it) which has an easy save to file option. (And resumes failed downloads too)
I don't know the answer to tar/gzip. My application uses zips instead and http://code.google.com/p/ziparchive/wiki/PageName does the trick.

Saving, reading, exchanging own file format?

any recommendations for saving four strings into an own file format that is read by the application and can be shared?
In my app, you will be able to enter some text in some boxes and the app shows a view with an background image and those strings. Now, I am already able to save this as a picture, but I actually want to save it to an own file format so that you can save different files that can be modified afterwards as well or even exchanged via email and opened from another iphone with the app.
Now, I wrote the code for accessing the documents folder of the app, as well as saving and deleting. Thing is, i dont know how to store those strings in a file (perhaps in a xml?) and read them easily afterwards from my application.
For the exchanging part, I found that link which would be a nice feature indeed: http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
Parsing xml seems not that difficult (never done it before): http://ipad.about.com/od/iPad-App-Dev/a/How-To-Parse-Xml-Files-In-Xcode-Objective-C.htm
If it's only a small bit of infomation then the easiest way to store your data in a file would be using a plist - there's a good tutorial here - http://www.icodeblog.com/2009/02/14/loading-data-from-plist-files/
In addition to the plist, you could also do the following approaches:
1) simplest - open a file in your documents directory, write the 4 strings (using whatever delimiter/end of string marker is useful - carriage return?) and overwrite them each time through. (i.e. it's your file, you can format it how you like)
2) mildly harder - use Apple's NSArchive to pack and unpack the strings.
3) possible overkill - store them directly in a SQLite database
4) major overkill - store them in CoreData.
Of course, the "overkill" options also provide you with extra features which may be of use if your app functionality extends beyond what you've outlined.
By sharing, I would think that simple copy and paste might be enough, but there's also sending it via email, or tripping another app's URL scheme to make it open it and sending the strings as part of the URL. You'd have to know that the other app would be able to interpret your strings as part of the URL, so you might have to write it yourself.
Okay guys I found that very nice method in the NSString documentation:
–writeToFile:atomically:encoding:error:
I think I am gonna separate my strings by /n and save them to a .txt. When I am gonna read the file afterwards, i am getting the string, divide it to substrings. That will do it, I guess.
One last question: Is it possible to replace the content of my file so that I won't need to create a new file every time i want to change something?
Thanks!

iOS text editor - save/load data model design?

I'm currently developing a simple text editor for iPad, and only save/load data parts are left. As a novice programmer, I don't have any experience with data managements in other languages and development environments. I researched on Core Data for a week and implemented a basic auto save/load feature in my app. But I have questions about better design of a text editor's data management such as saving text to *.txt files.
Which way is better? How do other text editors
1) Saving/Loading text as *.txt files
I found that in iOS 3.2 and later, the app can save and load (sync) texts as *.txt files into its local folder, so the users can load files in iTunes easily.
My question is that to implement save/load features, can I just save each text as *.txt file in my local folder and load them when launching my app? Specifically, can I just load titles of each *.txt file and load the entire NSString content only if the user clicks the specific file in UITableView??
So it doesn't use Core Data (or maybe Core Data is just used for a current text for auto save).
2) Core Data
Or using only Core Data is better approach? So when only the users want to save text to a *.txt file, the app saves a Core Data object or NSString content to *.txt file. In other words, unless the users manually save text as *.txt files, the users can't see any *.txt file in iTunes because Core Data internally saves them.
3) Both 1) + 2)
Would it better to save text as *.txt files and also using Core Data? I think it's just wasteful though.
Sorry for long questions. Thank you!
Apple strongly suggests in their Human Interface Guidelines that your users must not have "press save" to save, but rather saves should be automatic. At this point, iOS users do indeed expect that behavior. Core Data and autosave work really well together. (Core Data is also great for implementing Undo/Redo functionality as well.)
Therefore, I would suggest using Core Data as the app's internal format but offering the ability to export to other formats, like .txt. They are really not mutually exclusive methods. To export .txt files, you would create the .txt file in memory and then write it to your app's documents directory, which is what iTunes reads from. It's not very complicated.
Good luck!
I think you should use text files. So you can save space and sync into iTunes.