With iOS8 and extensions Apple introduced the App group containers (more info here).
We use it through NSFileManager
\'s
It doesn't make it clear the the docs but I found that the group identifier is case sensitive.
I find containerURLForSecurityApplicationGroupIdentifier can do work both on real device and simulator with xcode 6.2. I came across into this thread because i also got nil, but now i find the root cause is my typing error of the 'App Groups' name.
More, here is the list you need check:
The Method containerURLForSecurityApplicationGroupIdentifier:
works in my Simulator. But if i delete all files in the group folder (in case a user performs a logout in my app) the method returns nil on the next RUN in Xcode 6.1. I tested this with Xcode 6.2 and iOS SDK 8.2 Beta as well but it doesn't work.
The Code runs fine on a real device.
I also tried the above solutions without success.
I was able to solve this problem on my side. The documentation says
Your app must have a com.apple.security.application-groups entitlement for the specified application group. https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/index.html#//apple_ref/occ/instm/NSFileManager/containerURLForSecurityApplicationGroupIdentifier:
At some point in my app, I had removed the entitlements file from my app target/build settings/code signing/code signing entitlements . Both debug and release must include YOUR_APP.entitlements file . My debug wasn't including it so it wasn't working on simulator
I've found that the reason of this error in my case was a file ".com.apple.mobile_container_manager.metadata.plist". After I've got my file from this directory, I deleted all files in it. So this file was deleted also. And when you delete this file, app returns you a nil
for containerURLForSecurityApplicationGroupIdentifier
So I changed my code to this:
NSURL *groupPath = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:YGGroupIdentifier];
NSArray *fileArray = [fileManager contentsOfDirectoryAtPath:[groupPath path] error:nil];
for (NSString *filename in fileArray) {
if (![filename hasPrefix:@".com"]) {
[fileManager removeItemAtPath:[[groupPath path] stringByAppendingPathComponent:filename] error:nil];
}
}
Now it works great, even in simulator.
For me there was some mess with my iOS Team Provisioning Profile (which is not required to run in Simulator).
In order to run my app on my iPhone I had to first reconfigure the iOS Team Provisioning Profile for the Debug environment. Calling containerURLForSecurityApplicationGroupIdentifier:
worked perfectly fine on the device. Afterwards I went back to the Simulator and - there you go - it worked again as well.