如何在Xcode项目中使用具有多个环境的AppGroup?

发布于 2025-01-23 18:16:25 字数 861 浏览 3 评论 0原文

我有一个带有通知服务的iOS应用程序和Coredata。我使用的是应用程序组(group.com.example.appname)

我对应用程序设置了多个配置,以便我可以拥有一个开发和产品环境:

Debug Dev
Debug Prod
Release Dev
Release Prod

并且我已经修改了我的方案,并且在构建设置下的目标中,我有以下内容包装中的产品捆绑包标识符:

Debug Dev - com.example.appName.dev
Debug Prod - com.example.appName
Release Dev - com.example.appName.dev
Release Prod - com.example.appName

一切正常,我能够构建两个应用程序的版本。问题是我正在使用应用程序组进行通知extension,还因为我希望Coredata可以在我正在初始化Coredata堆栈的扩展中访问:

let groupName = "group.com.example.appName"
let databaseIdentifier = "appName.sqlite"
let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: groupName)!.appendingPathComponent(databaseIdentifier)

我如何能够更改Dev环境的组名称,以便相同数据库未与两个应用程序共享?

我是否需要创建另一个名为group.com.example.appname.dev的组?如果是这样,我该如何指定开发环境使用此组?

I have an iOS app with a NotificationServices extension and CoreData. I am using app groups (group.com.example.appName)

I have setup multiple configurations for my app so that I can have a dev and prod environment:

Debug Dev
Debug Prod
Release Dev
Release Prod

And I have modified my Scheme and in the target under build settings I have the following Product Bundle Identifiers in Packaging:

Debug Dev - com.example.appName.dev
Debug Prod - com.example.appName
Release Dev - com.example.appName.dev
Release Prod - com.example.appName

Everything works fine and I am able to build two versions of the app. The problem is that I am using app Groups for my NotificationExtension and also because I like CoreData to be accessible in the extension I am initializing my CoreData stack with:

let groupName = "group.com.example.appName"
let databaseIdentifier = "appName.sqlite"
let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: groupName)!.appendingPathComponent(databaseIdentifier)

How would I be able to change the group name for the dev environment so that the same database is not shared with the two apps?

Do I need to create another group called group.com.example.appName.dev? And if so how do I specify that the dev environment uses this group?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青衫负雪 2025-01-30 18:16:26

您可以尝试:

if let appDomain = Bundle.main.bundleIdentifier {
       let databaseIdentifier = "\(appDomain).sqlite"
       let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appDomain).appendingPathComponent(databaseIdentifier)
        }

you can try it:

if let appDomain = Bundle.main.bundleIdentifier {
       let databaseIdentifier = "\(appDomain).sqlite"
       let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appDomain).appendingPathComponent(databaseIdentifier)
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文