0

I have an app that needs to read some input data from a text file (a simple int array). Is it possible to copy the desired text file to the iPhone via itunes, and then access it from the app?

(I want to enable the possibility of adding any input I want, and not just to store it in the resources folder)

I looked for this topic and ended with some explanations about the 'app sandbox', but never understood how to find the acual path for the file. Any information would be very appreciated.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
U_D
  • 711
  • 1
  • 10
  • 18

3 Answers3

1

If you want to use iTunes for transferring files, you should do like this:

  1. Add the Info.plist key UIFileSharingEnabled and set it to YES.
  2. You will then expose your app's Documents directory through iTunes when connected. It can be used for file transfer in both directions.

In you code, you will get the path to the Documents directory by this method:

NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [pathArray objectAtIndex: 0];
Magnus
  • 857
  • 1
  • 10
  • 27
1

See this awesome post at RayWenderlich.com:

http://www.raywenderlich.com/1948/itunes-tutorial-for-ios-how-to-integrate-itunes-file-sharing-with-your-ios-app

It's exactly what you need.

Hope it helps, regards

ricky.tribbia
  • 124
  • 10
0

You can enable iTunes File Sharing in your app's Info.plist file by setting the UIFileSharingEnabled key, and copy files to your app through iTunes. It will be accessible from the Documents directory in the app bundle.

This should work both ways- so if you edit the file through the app and write it back to the Documents directory you can copy it back from your app through iTunes.

This question has a good description of the app sandbox, the Documents directory and access. What is the documents directory (NSDocumentDirectory)?

I did this recently to import some location-specific test data from a .CSV file in to my app to take to client demos, everyone on the team found it easy to use, and worked really well.

There's a great tutorial on iTunes File Sharing on the Ray Wenderlich site.

Community
  • 1
  • 1
Sam Meadley
  • 227
  • 1
  • 10