[英]Saving files from an iOS app extension to the containing app
I'm working on adding the ability to use the share button to allow users to save files for use with my main application. 我正在努力添加使用共享按钮的功能,以允许用户保存文件以供我的主应用程序使用。 Multiple file types (image, video, audio, pdf, etc) need to be supported. 需要支持多种文件类型(图像,视频,音频,PDF等)。
A general use case would be: The user takes a picture with the standard Camera app or audio recording using the Voice Memos app. 一般用例是:用户使用语音备忘录应用程序使用标准相机应用程序或录音进行拍照。 User clicks the Share button and selects my extension from the share list. 用户单击“共享”按钮并从共享列表中选择我的扩展名。 Dialog opens up giving the user to opportunity to give a description for the file. Dialog打开,让用户有机会给出文件的描述。 File is saved to where my main app (the containing app) can later access and process it. 文件保存到我的主应用程序(包含应用程序)以后可以访问和处理它的位置。
I've been able to get to the point where I am prompted to share the file, but I have not been able to find a location to successfully save to that my main app can later read from. 我已经能够到达提示我共享文件的位置,但是我无法找到成功保存到我的主应用程序以后可以读取的位置。 Is this even possible? 这甚至可能吗? Is there a better way to handle this scenario? 有没有更好的方法来处理这种情况?
I am currently doing this using Xamarin so debugging is not supported (and logging is minimal). 我目前正在使用Xamarin进行此操作,因此不支持调试(并且记录很少)。 If someone has an answer in Objective C, that would at least help point me in the right direction. 如果有人在目标C中得到答案,那至少会帮助我指出正确的方向。
There are a few things that you need to do. 您需要做一些事情。
First, your app and your app extension should belong to the same app group: 首先,您的应用和应用扩展程序应属于同一个应用组:
https://developer.apple.com/library/prerelease/ios/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingAppSandbox.html#//apple_ref/doc/uid/TP40011195-CH4-SW19 https://developer.apple.com/library/prerelease/ios/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingAppSandbox.html#//apple_ref/doc/uid/TP40011195-CH4-SW19
Then you can access the shared storage with something like this: 然后,您可以使用以下内容访问共享存储:
var groupUrl = NSFileManager.DefaultManager.GetContainerUrl ("stackoverflow.com.mygroup")
Now you can access files in the directory pointed by groupUrl. 现在,您可以访问groupUrl指向的目录中的文件。
Xamarin为iOS创建共享扩展的指南: http : //developer.xamarin.com/guides/ios/platform_features/introduction_to_extensions/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.