[英]Receiving files from other iOS apps with Copy In
I would like my app to receive .wav files from the files.app app.我希望我的应用程序从 files.app 应用程序接收 .wav 文件。 I added com.microsoft.waveform-audio to the Document Types array in Info.plist, and my app shows up in the share action sheet as “Open In X” ( not Copy In ).
我将 com.microsoft.waveform-audio 添加到 Info.plist 中的 Document Types 数组,并且我的应用程序在共享操作表中显示为“Open In X”(而不是 Copy In )。 I want to actually copy the files in, not open them in place, and the os will not allow me to copy these (error code 257).
我想实际复制文件,而不是原地打开它们,操作系统不允许我复制这些文件(错误代码 257)。 I'm trying to copy the file in the UIApplicationLaunchOptionsURLKey Path, but no go.
我正在尝试复制 UIApplicationLaunchOptionsURLKey 路径中的文件,但没有成功。
The launchOptions dictionary contains a RequireOpenInPlace=1 as well, in the applicationDidLaunch WithOptions. launchOptions 字典在 applicationDidLaunch WithOptions 中也包含 RequireOpenInPlace=1。
How do I let other apps copy files to mine with the UIActivityViewController?如何让其他应用程序使用 UIActivityViewController 将文件复制到我的?
If you are opening the file "in place" (not copying) you should make the resource referenced by the url accessible to the process.如果您“就地”打开文件(而不是复制),您应该使 url 引用的资源可以被进程访问。
Try calling url.startAccessingSecurityScopedResource()
before accessing the file.在访问文件之前尝试调用
url.startAccessingSecurityScopedResource()
。 Then you should be able to copy the file.然后您应该能够复制该文件。
Don't forget to balance the call with url.stopAccessingSecurityScopedResource()
when you don't need the file anymore.当您不再需要该文件时,不要忘记使用
url.stopAccessingSecurityScopedResource()
平衡调用。
Reference: https://developer.apple.com/documentation/foundation/nsurl#1663809参考: https : //developer.apple.com/documentation/foundation/nsurl#1663809
Edit: Another solution might be if you set LSSupportsOpeningDocumentsInPlace
to NO
in your Info.plist.编辑:另一种解决方案可能是,如果您在 Info.plist 中将
LSSupportsOpeningDocumentsInPlace
设置为NO
。 Then you would always see "Copy to XYZ" in share sheet and so will system copy the file to your Documents/Inbox folder in your app sandbox.然后您将始终在共享表中看到“复制到 XYZ”,因此系统会将文件复制到您的应用程序沙箱中的 Documents/Inbox 文件夹中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.