【发布时间】:2020-08-20 01:17:51
【问题描述】:
我正在开发 iOS 应用程序(使用 Xamarin)。我尝试用我的应用程序处理 pdf 文件并访问他们的内容。我将我的应用程序添加到 pdf 文件的上下文菜单(“打开方式...”),就像这里 https://i.stack.imgur.com/yowSw.png
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>PDF</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSItemContentTypes</key>
<array>
<string>com.adobe.pdf</string>
</array>
</dict>
</array>
当我点击“在我的应用程序中打开”时,我的应用程序打开并尝试访问文件的字节数组内容。
在 SceneDelegate 中,我添加了
[Export("scene:openURLContexts:")]
public void OpenUrlContexts(UIScene scene, NSSet<UIOpenUrlContext> urlContexts)
{
var path = urlContexts.AnyObject.Path;
var fileBytes = File.ReadAllBytes(path);
}
路径看起来像: file:///private/var/mobile/Containers/Shared/AppGroup/XXX/File%20Provider%20Storage/sample.pdf
不幸的是,读取会引发异常: System.UnauthorizedAccessException: '访问路径“/private/var/mobile/Containers/Shared/AppGroup/XXX/File Provider Storage/sample.pdf”被拒绝。'
如何访问以这种方式打开的文件的字节内容?
【问题讨论】:
-
您是否使用应用组或共享扩展在应用之间共享文件?
标签: ios iphone xamarin xamarin.ios