Lets say I have written an application for iOS which allows the user to enter some text and save it. How can I export this text to be viewed on a desktop PC running windows OS? If this is not possible, what are the alternatives?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can save the text to your app’s Documents directory and allow them to export it through iTunes. You can also allow them to email it.
Saving it to disk:
To save in the App’s documents directory, you’ll need to do a few things. First of all, you’ll need to get the URL to the path directory. A method for this is conveniently generated by Xcode when you make a Core Data based project. Here’s that method:
Next, you’ll want to take that that URL and use it to write our to your App’s documents directory. In the simples case, we have a string, called
someText, which we’ll be writing out to the Documents directory. Here’s what that looks like:We have a path, called
path. Note that we take the path to the documents directory and then append a filename. You could replacesomeText.txtwith whatever filename you want to use.We tell the the string to write itself out to the file (in this case atomically) and if it fails, we populate the
errorobject, which we can read out later if necessary. Note the option for “atomically” here. If it’s set toYES, the app will write the text into a buffer and rename it afterward. If it’s not set toYES, the text will be written straight to text. This makes a difference in multithreaded environments and can protect your text from being some mangled result, but atomic writing is slower.Here’s all of the above code at once:
Reading the file from iTunes:
This is the fun part. In Xcode, you need to add a key to your app’s Info.plist file. Here’s what that is going to look like in Xcode 4:
Now, in iTunes, your App’s documents directory will be visible.
Alternatively (or in addition to iTunes), you could use the MessageUI framework and allow the user to email the file.