swift - 查找 App Group 路径时返回 nil

标签 swift xcode

我启用了 App Group 并创建了一个名为“group.com.classData”的组 enter image description here

我的代码是这样的:

let plistPath3 = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.classData")
print(plistPath3) //returns "nil"

它返回零。为什么会这样?

最佳答案

我在开发共享扩展时遇到了这个错误。事实证明,虽然我已将 App Group 权利添加到 app 的 目标,但我没有将其添加到 extension 的 目标。我需要从项目/目标下拉列表中选择扩展:

A screenshot of Xcode that shows the location of the dropdown list with the projects and targets.

然后我单击“功能”选项卡并启用应用程序组。我为应用程序创建的应用程序组已经在列表中;我只需要检查它的复选框。当我再次运行该应用程序时,containerURL(forSecurityApplicationGroupIdentifier:) 返回了一个非零值。

关于swift - 查找 App Group 路径时返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43035717/

相关文章:

ios - Facebook Login Swift 无法在设备上运行(但可以在 IOS 模拟器上运行)

ios - 部署目标为 7.0 和 Xcode 7.1-7.2 的 iPhone4 中的启动屏幕为黑色

objective-c - 基于 NSDocument 的应用程序窗口位置

ios - 自动布局 - 如何添加 subview 以匹配 UIView 的大小?

swift - 文本未出现但 onAppear 触发

swift - UITextField 必须具有最少字符数才能激活 UIButton

ios - 快速更改 UISlider 的高度

swift - Realm 中的 NSPredicate - 在结果中搜索数组中的任何项目

ios - 如何为双长度 PseudoLanguage 提供应用内设置

ios - UITextField 不响应 iOS8 中的触摸?