开发者

How to implement iTunes built-in App "File Sharing" feature

I've noticed that several apps, when an iP* is connected, has a "File Sharing" feature inside of iTunes. Example applications are CloudReaders, Stanza, etc. This interface lets users Add files to the app and Save files from the app to their computers. Right now I've got a HTTP server running inside the app which lets users add files to it via Wi-Fi, but I'd like to support the aforementioned method as well.

Thanks to Art Gillespie, I got this working. Recently, I renamed my project and ended up having to dig around a bit again to figure out how to re-enable this since it went away.

This is how you do it.

  1. In your plist, add a new key for UIFileSharing. It should be listed as something like "Application supports iTunes file sharing".
  2. Build your code in "Release" mode.
  3. Go to the build/Release-iphoneos/ folder of your project and drag开发者_开发知识库 the appname file (not the .dSYM one) to iTunes. Click "Yes" if it asks about replacing.
  4. Now if you click on your device and go to "Apps" and scroll down you should see your app listed in the "File Sharing"'s Apps list.


You want to add the UIFileSharingEnabled key to your app's Info.plist

Sharing Files With The User


In the new Xcode, you can do this in the UI:

  1. Select your project in top left
  2. Select target in next column
  3. Click on Info tab
  4. In Custom iOS Target Properties, hover mouse over any row and click +
  5. In popup, select "Application supports iTunes file sharing", then set Value to YES on right
  6. Click Validate Settings at bottom to make sure all is good


According to apple doc:

File-Sharing Support
File-sharing support lets apps make user data files available in iTunes 9.1 and later. An app that declares its support for file sharing makes the contents of its /Documents directory available to the user. The user can then move files in and out of this directory as needed from iTunes. This feature does not allow your app to share files with other apps on the same device; that behavior requires the pasteboard or a document interaction controller object.

To enable file sharing for your app, do the following:

  1. Add the UIFileSharingEnabled key to your app’s Info.plist file, and set the value of the key to YES.

  2. Put whatever files you want to share in your app’s Documents directory.

  3. When the device is plugged into the user’s computer, iTunes displays a File Sharing section in the Apps tab of the selected device.

  4. The user can add files to this directory or move files to the desktop.

Apps that support file sharing should be able to recognize when files have been added to the Documents directory and respond appropriately. For example, your app might make the contents of any new files available from its interface. You should never present the user with the list of files in this directory and ask them to decide what to do with those files.

For additional information about the UIFileSharingEnabled key, see Information Property List Key Reference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜