With iOS8 and extensions Apple introduced the App group containers (more info here).
We use it through NSFileManager
's containerURLForSecurityApplicationGroupIdentifier:
method. It works well in production on AppStore (with both iOS8 and iOS7). Problem is since our team updated to Xcode 6.1 (6A1052d)
, the method returns nil
on Simulators.
We searched a lot but we didn't manage to find any clues. Even this question or this one are not applicable here.
Does NSFileManager
's containerURLForSecurityApplicationGroupIdentifier:
method works on your simulators? Is there any way to fix that?
The method containerURLForSecurityApplicationGroupIdentifier:
works in both device and Simulator.
If you have setup both targets (or Target and WatchKit Extension for instance) that are going to share data to support Groups, and it keeps returning nil, you may want to check your Targets settings.
Target Settings > General > Team > yourCompany signing team should be selected here. If there is a warning and a Fix This Issue button, be good and fix the issue by hitting it :)
Target Settings > Capabilities > App Groups > Is On + shows your group.com.yourcompany.yourapp.sharedContainter group name ("sharedContainer" is my choice name) is selected and is on black (not red). If it's red or there is a warning and Fix This Issue button, renew the group or create a different one.
Target Settings > Build Settings > Code Signing > Code Signing Entitlements: points to your entitlements files for both Debug and Release (something like yourApp/yourApp.entitlements)
Target Settings > Build Settings > Code Signing > Code Signing Identity: Make sure the identity is part of the Team selected above. I use iOS Developer.
Target Settings > Build Settings > Code Signing > Provisioning Profile: As above, make sure the PP you are using is of the Team required. I set it to Automatic.
Check those for both targets sharing data.
I hope it helps
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
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With