{%Pragmatic Coding%} Tips and tricks for software developers.


Simple iTunes File Sharing with iOS App

Recently I had to implement File sharing with the second version of my iPad application and it become easier than I thought.

I found out great opportunity that gives  iOS 4 +  with new functionality allowing you to enable file sharing between your apps and iTunes.  There are just a few steps that need to be done to get this functionality working just right.

So, as an example I had to made file sharing of CSV file where my application collect specific information about customers.

First of all you need to create manually CSV file you want to share in your Resources folder as shown below.

On applicationDidFinishLaunching you need to check if such file exists or not, if it does do nothing or whatever you want to do, if it doesn't you have to make a copy of generic file from your to the shared folder. Here is a code example how to do that:

Enable File Sharing in the Info.plist

Finally open up App-Info.plist and add a new boolean key called "UIFileSharingEnabled" or "Application supports iTunes file sharing" and make sure it’s checked:

Build and run your project, and make sure you install it on your iPhone or iPad (i.e. not your Simulator), because File Sharing only works with iTunes on a physical device.
Next go ahead and fill your file with data.
You can test that the OS detected your “UIFileSharingEnabled” flag by loading up iTunes, switching to the Apps Tab, and scrolling down: you should see your app there as long as your device is connected.
If it doesn’t show up, try deleting the app from your device and re-installing, and synching iTunes.
You should see  you shared file in Documents window.
Then in File Sharing in iTunes you can download this file and open with Excel.

Have a nice coding! :)

Share on social network

Share to Facebook
Share to Google Plus
Share to LiveJournal
Share to MyWorld
Share to Odnoklassniki
Share to Yandex
Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

No trackbacks yet.