erikberglund / SwiftPrivilegedHelper

Example application using a privileged helper tool with authentication in an unsandboxed application written in Swift
MIT License
180 stars 33 forks source link

A method can't be called in HelperProtocol? #25

Closed diuming closed 4 years ago

diuming commented 4 years ago

I add a function in HelperProtocol, but openFile never be called. Could you give me advice?

@objc(HelperProtocol)
protocol HelperProtocol {
    func getVersion(completion: @escaping (String) -> Void)
    func openFile(completion: @escaping (UnsafeMutablePointer<FILE>?) -> Void)
}

func openFile(completion: @escaping (UnsafeMutablePointer<FILE>?) -> Void) {
        var file = fopen("/dev/auditpipe", "r")
        completion(file)
}
jeff-h commented 4 years ago

Does the compiler throw an error?

If it seems to be silently failing, in my experience there's a good chance you're just not getting to see what's happening inside your helper, since it's a second process.

It's possible to ask Xcode to debug both processes. One method is: Debug > Attach to Process by PID or Name... and entering as the name com.github.erikberglund.SwiftPrivilegedHelper:

image

Incidentally, I am sure there'd be a way to have Xcode do this every time, instead of having to tell it via Attach to Process by PID or Name.... Can anyone enlighten me? :)