我有一个iOS应用程序与NotificationServices扩展和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
一切都很好,我能够构建两个版本的应用程序。问题是,我正在使用应用程序组为我的NotificationExtension,也因为我喜欢CoreData可以在扩展中访问,我正在初始化我的CoreData堆栈:
let groupName = "group.com.example.appName"
let databaseIdentifier = "appName.sqlite"
let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: groupName)!.appendingPathComponent(databaseIdentifier)
我如何能够改变组名称的开发环境,使相同的数据库不与两个应用程序共享?
我是否需要创建另一个名为group.com.example.appName.dev的组?如果是,我如何指定开发环境使用这个组?
你可以试试:
if let appDomain = Bundle.main.bundleIdentifier {
let databaseIdentifier = "(appDomain).sqlite"
let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appDomain).appendingPathComponent(databaseIdentifier)
}