I have trouble with reading a file from an App Group with my System Network Extension.
The app group container is found successfully.
However the file read returns empty.
In the app itself the same code runs fine and returns a string array of items found in the file.
Code:
Log:
Edit, after more digging:
fileURL is different!
App: file:///Users/me/Library/Group%20Containers/
SysExt: file:///private/var/root/Library/Group%20Containers/
The app group container is found successfully.
However the file read returns empty.
In the app itself the same code runs fine and returns a string array of items found in the file.
Code:
Code Block func readFile() -> [String] { var jsonResult: [String] = [] guard let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: AppConstants.groupID) else { fatalError() } let fileURL = containerURL.appendingPathComponent("file.json") if let data = try? NSData(contentsOfFile: fileURL.path, options: .mappedIfSafe) as Data { if let json = try? JSONSerialization.jsonObject(with: data, options: .fragmentsAllowed) { jsonResult = json as! [String] } } os_log("jsonResult: %{public}@", jsonResult) return jsonResult }
Log:
Code Block default 09:42:19.486793+0200 app-network-extension container_create_or_lookup_app_group_path_by_app_group_ identifier: success default 09:42:20.105792+0200 app-network-extension jsonResult: ( )
Edit, after more digging:
fileURL is different!
App: file:///Users/me/Library/Group%20Containers/
SysExt: file:///private/var/root/Library/Group%20Containers/