iOS,是否有一个临时目录,所有应用程序都可以看到?

时间:2022-09-20 15:11:54

Is there a temporary directory that all applications have access to in iOS so that files can be passed between them?

是否存在所有应用程序都可以在iOS中访问的临时目录,以便可以在它们之间传递文件?

Please Note: I understand the "Open In" menu of UIDocumentInteractionController. I'm hoping to pass a file by calling openURL on UIApplication instead. I'm trying NOT to use the "Open In" menu.

请注意:我理解UIDocumentInteractionController的“Open In”菜单。我希望通过在UIApplication上调用openURL来传递文件。我正在尝试不使用“打开”菜单。

2 个解决方案

#1


2  

As "Martin R" pointed out, there is no common directory anywhere that you can use for this purpose.

正如“Martin R”所指出的,在任何地方都没有可用于此目的的通用目录。

Since you have control over both apps, you do have a solution that will allow the two apps to share files and/or data. This will require that both apps be updated to support this feature.

由于您可以控制这两个应用程序,因此您确实拥有一个允许两个应用程序共享文件和/或数据的解决方案。这将要求更新这两个应用程序以支持此功能。

The solution involves the use of UIPasteBoard. You can either use the general pasteboard or you can use a "private" named pasteboard. If you use a named pasteboard, both apps need to agree on the name (or the name can be passed as part of the URL when you call openURL:).

解决方案涉及使用UIPasteBoard。您可以使用常规粘贴板,也可以使用“私有”命名粘贴板。如果您使用命名的粘贴板,则两个应用程序都需要就名称达成一致(或者当您调用openURL时,名称可以作为URL的一部分传递:)。

Have the source app call setData:forPasteBoardType: on the (named or general) pasteboard. Then the source app should create a URL to the other app. The URL should include a couple of query parameters that include the name of the pasteboard (if appropriate) as well as the pasteboard type used to set the data.

让源应用程序在(命名或常规)粘贴板上调用setData:forPasteBoardType:然后源应用程序应该创建另一个应用程序的URL。 URL应包含一些查询参数,其中包括粘贴板的名称(如果适用)以及用于设置数据的粘贴板类型。

When the receiving app is launched, it gets the query parameters and uses those to get the pasteboard and then the data with the proper type.

启动接收应用程序时,它会获取查询参数并使用这些参数获取粘贴板,然后使用正确类型的数据。

This solution may have issues if the file you need to pass gets to be too big. I've used this with multi-megabyte files. Since the data is being loaded in memory, the amount of data must have an upper limit. Please test properly on real devices with the largest files you expect to transfer.

如果您需要传递的文件太大,此解决方案可能会出现问题。我已将它用于多兆字节文件。由于数据正在加载到内存中,因此数据量必须具有上限。请在具有您希望传输的最大文件的真实设备上正确测试。

#2


4  

No there isn't. The only shared location (in some sense) is the Photo Library, which each application can use to load and save images (if the user permits it). Apart from that, each application has only access to its own Documents, Library etc. folders.

不,没有。唯一的共享位置(在某种意义上)是照片库,每个应用程序可以使用它来加载和保存图像(如果用户允许)。除此之外,每个应用程序只能访问自己的Documents,Library等文件夹。

(Of course I am not speaking about jailbroken devices.)

(当然,我不是在谈论越狱设备。)

#1


2  

As "Martin R" pointed out, there is no common directory anywhere that you can use for this purpose.

正如“Martin R”所指出的,在任何地方都没有可用于此目的的通用目录。

Since you have control over both apps, you do have a solution that will allow the two apps to share files and/or data. This will require that both apps be updated to support this feature.

由于您可以控制这两个应用程序,因此您确实拥有一个允许两个应用程序共享文件和/或数据的解决方案。这将要求更新这两个应用程序以支持此功能。

The solution involves the use of UIPasteBoard. You can either use the general pasteboard or you can use a "private" named pasteboard. If you use a named pasteboard, both apps need to agree on the name (or the name can be passed as part of the URL when you call openURL:).

解决方案涉及使用UIPasteBoard。您可以使用常规粘贴板,也可以使用“私有”命名粘贴板。如果您使用命名的粘贴板,则两个应用程序都需要就名称达成一致(或者当您调用openURL时,名称可以作为URL的一部分传递:)。

Have the source app call setData:forPasteBoardType: on the (named or general) pasteboard. Then the source app should create a URL to the other app. The URL should include a couple of query parameters that include the name of the pasteboard (if appropriate) as well as the pasteboard type used to set the data.

让源应用程序在(命名或常规)粘贴板上调用setData:forPasteBoardType:然后源应用程序应该创建另一个应用程序的URL。 URL应包含一些查询参数,其中包括粘贴板的名称(如果适用)以及用于设置数据的粘贴板类型。

When the receiving app is launched, it gets the query parameters and uses those to get the pasteboard and then the data with the proper type.

启动接收应用程序时,它会获取查询参数并使用这些参数获取粘贴板,然后使用正确类型的数据。

This solution may have issues if the file you need to pass gets to be too big. I've used this with multi-megabyte files. Since the data is being loaded in memory, the amount of data must have an upper limit. Please test properly on real devices with the largest files you expect to transfer.

如果您需要传递的文件太大,此解决方案可能会出现问题。我已将它用于多兆字节文件。由于数据正在加载到内存中,因此数据量必须具有上限。请在具有您希望传输的最大文件的真实设备上正确测试。

#2


4  

No there isn't. The only shared location (in some sense) is the Photo Library, which each application can use to load and save images (if the user permits it). Apart from that, each application has only access to its own Documents, Library etc. folders.

不,没有。唯一的共享位置(在某种意义上)是照片库,每个应用程序可以使用它来加载和保存图像(如果用户允许)。除此之外,每个应用程序只能访问自己的Documents,Library等文件夹。

(Of course I am not speaking about jailbroken devices.)

(当然,我不是在谈论越狱设备。)