gpt4 book ai didi

objective-c - 启用 AppSand 盒时如何从 USB 大容量存储设备读取数据

转载 作者:行者123 更新时间:2023-12-03 16:35:12 24 4
gpt4 key购买 nike

在我的应用中,当用户连接 USB 设备(手机)时,我使用 NSWorkspaceDidMountNotification 通知用户通过执行 NSAlert 检测到设备。

如果接受,应用程序将继续从设备复制(读取)文本文件内容。在我启用 AppSandbox 之前,这一切都很好。我已启用 USB 授权,但现在当应用程序尝试复制时,出现以下错误。

ERROR READING CONTENT OF FILE: Error Domain=NSCocoaErrorDomain Code=257 "The file “Office.txt” couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/Volumes/OfficeDrive//documents/Office.txt, NSUnderlyingError=0x600000049390 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

如果启用了 AppSandbox,是否可以从 USB 设备读取数据。

最佳答案

如果您处于沙盒状态,您只能访问用户明确授予访问权限的文件:

User-specified files. A sandboxed app (with an appropriate entitlement) automatically obtains access to files in arbitrary locations when those files are explicitly opened by the user or are dragged and dropped onto the application by the user.

( App Sandbox Design Guide )

因此,您必须打开一个文件对话框(可能已经指向您从通知中找出的位置)并让用户选择它才能获得访问权限。

远程相关的 SO 帖子:

关于objective-c - 启用 AppSand 盒时如何从 USB 大容量存储设备读取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35042355/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com