找到App Group的路径时返回nil

时间:2017-03-26 23:16:46

标签: swift xcode

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

我的代码看起来像这样:

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

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

1 个答案:

答案 0 :(得分:0)

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

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

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