简体   繁体   English

使用 Copy In 从其他 iOS 应用程序接收文件

[英]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.

相关问题 从其他应用程序和NotificationCenter接收有意义的通知 - Receiving meaningful notifications from other apps and NotificationCenter 读取属于其他Apps iOS的文件 - Reading Files belonging to other Apps iOS 访问ios应用程序文档和其他文件 - Access ios apps documents and other files ios-在qlpreviewcontroller或UIDocumentInteractionController中控制与其他应用程序的复制和共享文件 - ios - Control copy and share file with other apps in qlpreviewcontroller or UIDocumentInteractionController 如何使用简单的iOS操作扩展从React Native应用程序中的其他应用程序收集文件? - How to gather files from other apps in my React Native app with a simple iOS action extension? 阅读其他iOS应用的通知? - Read notifications from other iOS apps? 在自己的应用程序中从其他应用程序打开文件 - Open Files from other apps in own app iOS 7接收空投文件 - iOS 7 receiving airdrop files 是否可以在iOS / Android / Windows Phone中访问其他应用程序的文件? - Is it possible to access other apps' files in iOS/Android/Windows Phone? 将PHAsset从Gallery复制到iOS 9中的其他目录 - Copy PHAsset from Gallery to other directory in iOS 9
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM