【问题标题】:swift access to an app groupcontainer entitlement快速访问应用程序组容器权利
【发布时间】:2020-01-01 12:57:51
【问题描述】:

新年快乐。

我需要访问应用组容器中的 plist。

要在沙盒系统中获得访问权限,我应该怎么做才能让它正确。 我确实在Create directory in app group container swift 阅读然后回答,但在 XCode 11 中找不到相应的权利设置。

是否有相应的 URL 或路径(字符串)函数可以调用? 据我所知,没有 .groupContainerDirectory 选项可用。

现在我尝试使用以下代码...

let appIdentifier = "UBF8T346G9.Office"
    let fileManager = FileManager.default
    let container = fileManager.containerURL(forSecurityApplicationGroupIdentifier: appIdentifier)

    print("Container \(container)")
    do{
        if let container = container {

            let directoryPath  = container.appendingPathComponent("Profile Settings")

            var isDir : ObjCBool = false

            let path = directoryPath.path
            if fileManager.fileExists(atPath: path, isDirectory: &isDir) {
                if isDir.boolValue {
                    print("file exists and is a directory")
                    let plistPath = url.appendingPathComponent( "com.microsoft.visualbasic.plist").path
                    let plistDict = NSDictionary(contentsOfFile: plistPath)
                    if let dict = plistDict {
                       print("Dict: \(dict)") // <<<<<< Never comes here
                    }
                }
            } 
        }
    } catch let error as NSError {
        print(error.description)
    }
}

当然不起作用,因为我需要一些访问应用程序的“组容器”

谢谢。

【问题讨论】:

  • 以下主题Mac App Sandbox Group Container problems 应该会有所帮助。
  • 感谢您的反应,但我需要访问另一个应用程序的 Group Container 文件夹和 Plist。提到的链接确实显示了一些沙盒访问方法,但它在 XCode 11 中不存在。确实添加了额外的信息以显示 plist 返回为空。
  • 我应该在项目内的项目授权文件中使用相对路径创建一行 'com.apple.security.temporary-exception.files.home-relative-path.read-write' 键。阅读资料:developer.apple.com/library/archive/documentation/Miscellaneous/…

标签: macos swift5


【解决方案1】:

创建一个

com.apple.security.temporary-exception.files.home-relative-path.read-write

在 Xcode 中项目内的项目授权文件中的相对路径键。

阅读资料:https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/AppSandboxTemporaryExceptionEntitlements.html

【讨论】:

    猜你喜欢
    • 2017-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-19
    • 2017-04-27
    • 2016-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多