ios 如何为我的应用启用文件共享?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6029916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 19:57:27  来源:igfitidea点击:

How to enable file sharing for my app?

iosfile-sharing

提问by Proud Member

I have an image editing app where users can apply effects to photos. How could I enable it so that users can see my app in iTunes in the File Sharing tab and then just drag+drop photos to the app?

我有一个图像编辑应用程序,用户可以在其中对照片应用效果。我怎样才能启用它,以便用户可以在 iTunes 的“文件共享”选项卡中看到我的应用程序,然后只需将照片拖放到应用程序中?

Some of the eBook readers like Stanza works like this and it would be a cool option. Maybe someone can point out a tutorial or resource that talks about how to enable and use this technique.

一些像 Stanza 这样的电子书阅读器就是这样工作的,这将是一个很酷的选择。也许有人可以指出有关如何启用和使用此技术的教程或资源。

回答by Vin

You just have to set UIFileSharingEnabled(Application Supports iTunes file sharing) key in the info plist of your app. Here'sa link for the documentation. Scroll down to the file sharing support part.

您只需在应用程序的信息 plist 中设置UIFileSharingEnabled( Application Supports iTunes file sharing) 键。这是文档的链接。向下滚动到文件共享支持部分。

In the past, it was also necessary to define CFBundleDisplayName(Bundle Display Name), if it wasn't already there. More details here.

过去,还需要定义CFBundleDisplayName( Bundle Display Name),如果它还没有的话。更多细节在这里

回答by Nico

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 UIFileSharingEnabledkey to your app's Info.plist file, and set the value of the key to YES. (The actual key name is "Application supports iTunes file sharing")

  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.

文件共享支持
文件共享支持让应用程序可以在 iTunes 9.1 及更高版本中提供用户数据文件。声明支持文件共享的应用程序使其 /Documents 目录的内容可供用户使用。然后,用户可以根据需要从 iTunes 将文件移入和移出该目录。此功能不允许您的应用与同一设备上的其他应用共享文件;该行为需要粘贴板或文档交互控制器对象。

要为您的应用启用文件共享,请执行以下操作:

  1. UIFileSharingEnabled键添加到应用程序的 Info.plist 文件中,并将键的值设置为YES。(实际的关键名称是“应用程序支持 iTunes 文件共享”)

  2. 将您想要共享的任何文件放入应用程序的 Documents 目录中。

  3. 当设备插入用户的计算机时,iTunes 会在所选设备的应用程序选项卡中显示文件共享部分。

  4. 用户可以将文件添加到此目录或将文件移动到桌面。

支持文件共享的应用程序应该能够识别何时将文件添加到 Documents 目录并做出适当响应。例如,您的应用程序可能会从其界面中提供任何新文件的内容。您永远不应该向用户提供此目录中的文件列表,并要求他们决定如何处理这些文件。

有关 UIFileSharingEnabled 键的其他信息,请参阅信息属性列表键参考

回答by wanyancan

New XCode 7 will only require 'UIFileSharingEnabled' key in Info.plist. 'CFBundleDisplayName' is not required any more.

新的 XCode 7 只需要 Info.plist 中的“UIFileSharingEnabled”键。不再需要“CFBundleDisplayName”。

One more hint: do not only modify the Info.plist of the 'tests' target. The main app and the 'tests' have different Info.plist.

还有一个提示:不要只修改'tests'目标的Info.plist。主应用程序和“测试”具有不同的 Info.plist。

回答by Tim

If you find by alphabet in plist, it should be "Application supports iTunes file sharing".

如果您在 plist 中按字母查找,应该是“应用程序支持 iTunes 文件共享”。

回答by iVentis

Maybe it's obvious for you guys but I scratched my head for a while because the folder didn't show up in the files app. I actually needed to store something in the folder. you could achieve this by

也许这对你们来说很明显,但我挠了一阵子,因为该文件夹没有出现在文件应用程序中。我实际上需要在文件夹中存储一些东西。你可以通过实现这个

  • saving some files into your document directory of the app
  • move something from iCloud Drive to your app (in the move dialog the folder will show up). As soon as there are no files in your folder anymore, it's gonna disappear from the "on my iPad tab".
  • 将一些文件保存到应用程序的文档目录中
  • 将某些内容从 iCloud Drive 移动到您的应用程序(在移动对话框中,文件夹将显示)。一旦您的文件夹中不再有文件,它就会从“在我的 iPad 标签上”消失。

回答by oscar castellon

In Xcode 8.3.3 add new row in .plist with true value

在 Xcode 8.3.3 中用真值在 .plist 中添加新行

Application supports iTunes file sharing

应用程序支持iTunes文件共享