containerURLForSecurityApplicationGroupIdentifier getting nil value

不问归期 提交于 2019-12-05 10:11:06

Xcode6 (currently in beta) enforces the shared folder IDs to start with "group."

Sharing my CoreData store works for me with the following URL with Xcode6/iOS8 both beta.

NSFileManager* fileManager = [NSFileManager defaultManager];
NSURL* storeUrl = [fileManager containerURLForSecurityApplicationGroupIdentifier:@"group.XXX"];

It seems the documentation that stevesliva linked will be obsolete as soon as Xcode6 will be released

Well, I verified it in my own code. The Team Identifier shows up in the subdirectory of Library/Group Containers, so you do in fact need to include it in your code:

NSFileManager* fileManager = [NSFileManager defaultManager];
NSURL* storeUrl = [fileManager containerURLForSecurityApplicationGroupIdentifier:@"YOURTEAMID.com.xxxxxxxxxxx.catalogapp.Coredata"];
NSLog(@"%@", storeUrl);

What I'm not sure about is whether that's a required name-- it's not very user friendly-- or whether it's something Apple is recommending to make it super-unique.

As mentioned in the comment above, this was figured out starting with Apple's Application Sandbox Design Guide - Application Group Container Directory:

These group containers are automatically added into each app’s sandbox container as determined by the existence of these keys, and are stored in ~/Library/Group Containers/, where is the name of the group. The group name itself must begin with your development team ID, followed by a period.

In iOS 11, there is a better way to get shared container URL.

[NSFileProviderManager defaultManager].documentStorageURL

Make sure you're signing both your app and your extension with the same provisioning profile!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!