App Groups forSecurityApplicationGroupIdentifier returns nil
I had the same issue in the past. To fix FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: id)
being nil, just make sure that the entitlements that are being used for the debug (You can find this in your target's Build Settings) has the app group you made. Sometimes it's not added.
containerURLForSecurityApplicationGroupIdentifier returns nil on iOS Simulator
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
Swift - Widget not able to access app group
I found out what my problem was. I had accidentally selected the release tab under Signing & Capabilities. Which caused my app group to be wrong when checking on release, thus making the error occur.
I just had to select All and re-add the app groups capability which made it work again.
Create directory in app group container swift
containerURLForSecurityApplicationGroupIdentifier
returns the URL to the group container.
To create a directory append the new directory name as path component
let fileManager = NSFileManager.defaultManager()
if let directory = fileManager.containerURLForSecurityApplicationGroupIdentifier("APP_GROUP_IDENTIFIER") {
let newDirectory = directory.URLByAppendingPathComponent("MyDirectory")
try? fileManager.createDirectoryAtURL(newDirectory, withIntermediateDirectories: false, attributes: nil)
}
Swift 3:
let fileManager = FileManager.default
if let directory = fileManager.containerURL(forSecurityApplicationGroupIdentifier: "APP_GROUP_IDENTIFIER") {
let newDirectory = directory.appendingPathComponent("MyDirectory")
try? fileManager.createDirectory(at: newDirectory, withIntermediateDirectories: false, attributes: nil)
}
Access App Groups container directory from test runner
Actually, you can!
Simulator:
Write / duplicate your shared data to this location; it should be accessible to both the UITestRunner and your application. Remember to have a mechanism to ensure this does not make it to production code.
NSString * pathAsString = [NSProcessInfo processInfo].environment[@"SIMULATOR_SHARED_RESOURCES_DIRECTORY"];
Device:
Your UITestRunner should share the same Group Identifier as the app under test. Then you can access the shared resources folder. This does not work on Simulator because the UITestRunner is not signed for simulator targets, and it must be signed and part of the Shared Group in order to access the group.
NSURL *containerURL = [NSFileManager.defaultManager containerURLForSecurityApplicationGroupIdentifier:groupIdentifier];
Paulo Andrade has a nice blog post on how to do this:
https://pfandrade.me/blog/managing-ios-ui-testing-fixtures/
Related Topics
When Should I Use Anyobject Insted of Uibutton in Swift
Xcode 8 Memory Graph Says "No Selection" and Not Working
Swift iOS - Tag Collection View
How Parsing Firebase Fdatasnapshot JSON Data in Swift
How to Display Only Limited Photos with PHPickerviewcontroller
Swift Add Line Above to Control
Blur Effect - Background Uitextfield
Swift: Have Searchbar Search Through Both Sections and Not Combine Them
Diffabledatasource: Snapshot Doesn't Reload Headers & Footers
Nsubiquityidentitydidchangenotification and Sigkill
Swiftui How Add Custom Modifier with Callback
Why am I Getting Com.Facebook.Sdk.Login Error 308
Restkit, Coredata and Swift - I Can't Seem to Fetch Results Back Out
Swift 3 Nscache Generic Parameter 'Keytype' Could Not Be Inferred
Swift 3 - Nsfetchrequest Distinct Results
How to Auto Call an @Ibaction Function
How to Set Up Gccontroller Valuechangehandler Properly in Xcode