简体   繁体   English

将文件从iOS应用扩展程序保存到包含的应用

[英]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指向的目录中的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在iOS App包含扩展和扩展(不是主机应用程序)之间进行通信 - How to communicate between iOS App Containing Extension and Extension (not Host App) iOS 操作扩展无法打开包含应用程序 - iOS action extension cannot open containing app 如何使用应用程序扩展中的 IPC 将信息异步发送到 iOS 上的包含应用程序? - How can I use IPC from an app extension to asynchronously send information to the containing app on iOS? 如何检测在 iOS 8 上的包含应用程序中启用了应用程序扩展? - How to detect an app extension is enabled in containing app on iOS 8? 从 iOS 共享扩展中保存文件以供主机应用程序使用 - Save files from iOS share extension for use by host app app扩展如何访问包含app Documents /文件夹的文件 - How can app extension access files in containing app Documents/ folder iOS - 在plist文件中保存应用购买数据? - iOS - saving in app purchase data in plist files? IOS应用程序和手表扩展之间的共享文件 - Shared files between IOS app and watch extension 发布NSUserDefaults在iOS键盘扩展和包含应用之间进行更改吗? - Post NSUserDefaults changes between iOS Keyboard Extension and Containing app? 编译包含iOS 8 App Extension的Xcode项目时生成错误 - Build error when compiling Xcode project containing iOS 8 App Extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM