首页 > 解决方案 > 快速访问应用程序组容器权利

问题描述

你好新年的人们。

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

要在沙盒系统中获得访问权限,我应该怎么做才能让它正确。我确实在应用程序组容器中的创建目录中快速阅读然后回答,但在 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)
    }
}

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

谢谢你。

标签: macosswift5

解决方案


创建一个

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


推荐阅读