I am using the below code snippet to get the system preferences firewall status wheter it is ON/OFF using system .plist file.
func getFirewallStatus() -> Bool {
let paths = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .systemDomainMask, true)
var path = paths[0]
path = "\(path)/\("Preferences/com.apple.alf.plist")"
path = path.replacingOccurrences(of: "/System", with: "")
let _dictionary = NSDictionary(contentsOfFile: path)
// firewall status
let status = (_dictionary["globalstate"] as? NSNumber)?.intValue ?? 0
if status == 0 {
return false
}
return true
}
Sandbox disable(Xcode): In this case, I am able to get the firewall status (On/Off).
Sandbox enable(Xcode): app is crashing when accessing the contents of file.
let _dictionary = NSDictionary(contentsOfFile: path)
Please let me know the reasons, why app is crashing in case of sandbox enable mode?
My intention is to get the status of firewall and not to update any system preferences config.
Thanks in advance!