在Swift/iOS中的应用程序之间共享文件数据 [英] Sharing File Data Between Applications in Swift/iOS

查看:618
本文介绍了在Swift/iOS中的应用程序之间共享文件数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究如何安全地在应用程序之间共享数据.在深入研究使用错误方法的实现之前,我想获得一些正确方法的信息.仅仅因为您可以做某事并不一定意味着您应该做.

I've been doing research on how to share data between applications securely. I'd like to get some info on the correct way to handle this before I do a deep dive on implementation using the wrong method. Just cause you can do something does not necessarily mean you should.

用户案例:我正在开发一套语言学习应用程序,这些应用程序具有数百个音频文件和json文件的共享音频文件库,其中包含与一种语言相对应的重要数据.我希望用户在使用我们套件中的另一个应用程序时不必重新下载语言包.

User Case: I am working on a suite of language learning apps that have a shared audio file base of several hundred audio files and json files containing important data corresponding to a language. I'd prefer to allow the user to not have to re-download the language bundle when they use another app in our suite.

1.应用程序扩展-文档提供商非UI变体

根据

文件提供程序扩展程序通过打开和移动操作授予对主机应用程序沙箱外部文件的访问权限.此扩展名(有时在这里简称为文件提供程序)也允许主机应用下载文件而无需提供文档选择器视图控制器.此功能使主机应用程序可以使用安全的URL书签访问以前打开的文档,即使这些文件不再存储在设备上也是如此.

The File Provider extension grants access to files outside the host app’s sandbox with the open and move actions. This extension (sometimes shortened here to file provider) also allows the host app to download files without presenting a document picker view controller. This feature lets the host app access previously opened documents using secure URL bookmarks, even if those files are no longer stored on the device.

从表面上看,这似乎是一个切实可行的解决方案.我主要关心的是最后几行,其中指出应用程序可以下载不再存储在设备上的文件.我希望将文件存储在本地设备上,以防止持续下载.如果文档提供者确实将文件存储在本地,并允许组中的各种应用程序访问文件,那么我认为这可以工作.

On the surface this seems like a really solid solution. My main concern stems from the last couple lines where it state that the application can download the files no longer stored on the device. I want the files to be stored locally on the device to prevent constant downloading. If the Document Provider does store the files locally and allow the various applications in the group to access the files, then I think this could work.

2.共享钥匙串访问

使您可以安全地将数据存储到共享钥匙串中,作为一组应用程序一部分的其他应用程序可以访问该共享钥匙串.共享钥匙串访问的所有应用程序必须使用相同的应用程序ID前缀.有关操作中共享钥匙串访问的示例.

Allows you to securely store data to a shared keychain that other applications that are part of a suite of applications can access. All applications that share keychain access must use the same app ID prefix. For an example of shared keychain access in action.

我已经仔细阅读了该文档的文档,我认为这可能是最合适的.这个解决方案的主要问题是上传的数据是否有大小限制,以及是否允许mp3/ogg/json文件类型.我在此解决方案中发现的大多数示例/用法都指向共享字符串和小数据,我不确定它是否会处理json或音频文件之类的大数据.

I've looked a little into the documentation of this one, and I think this might be the best fit. My major concern with this solution is whether or not there is a size limit to the data uploaded and if mp3/ogg/json file types are allowed. Most the examples/uses I have found with this solution point to sharing strings and small data, I am not sure if it will handle large data like json or audio files.

我还发现此存储库显然使与钥匙串的处理更加容易:

I also found this repo that apparently makes dealing with Keychain easier:

3.自定义粘贴板

自定义粘贴板最适合在两个应用程序之间半私人共享自定义数据的目的.使用唯一名称标识自定义粘贴板.它们可以将数据保留在创建它们的应用程序之外,从而使粘贴板可以在应用程序终止后甚至在重新启动设备后保留数据.

The custom pasteboard is best for the purpose of semi-privately sharing custom data between two applications. Custom pasteboards are identified using unique names. They can persist data beyond the application that creates them, allowing a pasteboard to hold onto data after the application is terminated or even after rebooting the device.

在粘贴板上进行数据读写时,必须指定粘贴板类型.粘贴板类型通常使用统一类型标识符(UTI)来识别进入和从粘贴板检索的数据的类型.有关其他信息,请参阅Apple的UIPasteboard类参考文档.

When writing or reading data to and from a pasteboard, you must specify a pasteboard type. Pasteboard types typically use a uniform type identifier (UTI) to identify the type of data going into and being retrieved from the pasteboard. See Apple’s UIPasteboard Class Reference documentation for additional information.

以上文档摘自此帖子

我对这种解决方案的主要担心是,这可能有点麻烦.从逻辑上讲,粘贴板看起来像是一种临时保存数据并允许在应用之间共享的东西,而我正在寻找的解决方案需要更多的是永久解决方案.

My main concern with this solution is that perhaps it is a bit of a hack. Logically a pasteboard seems like something that temporarily holds data and allows sharing between apps, whereas the solution I am looking for needs to be more of a permanent solution.

对于在应用之间共享这些类型的文件的最佳做法的任何信息,我将不胜感激.我认为这里还有很多其他解决方案,因此,如果有更好的选择,我希望了解一些信息.如果发生这种情况,我在这里列出的一种解决方案是解决此问题的好方法,我很乐意向您提供有关您与他们合作的经验的更多信息,以及我对他们的担忧是否有效,或者没有什么可担心的.

I'd appreciate any info on best practices towards sharing these types of files between apps. I assume there are plenty of other solutions I've omitted here, so if there is a better alternative I'd love some info on it. If it happens one of the listed solutions I have placed here is a good way to solve this problem I'd love to have some more info on your experience with working with them and if my concerns with them are valid, or nothing to worry about.

提前.一如既往,写得好的答案会得到投票;)

Thx in advance. As always, well written answers get up-votes ;)

推荐答案

我认为最好的方法是通过设置应用程序组来实现数据共享.这是Apple推荐的用于在应用程序和扩展之间共享数据的解决方案,而且我相信总体上可以在应用程序之间共享数据.

I believe the best approach would be to enable data sharing by setting up an app group. This is Apple's recommended solution for sharing data between applications and extensions, and I believe for sharing data between apps in general.

请参阅通过包含的应用共享数据"

另请参阅"

这篇关于在Swift/iOS中的应用程序之间共享文件数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆