How to End / Reset an XPC Assistant Package?

Does anyone know how to complete or reset the XPC helper? According to Apple documentation, startd takes care of the XPC help if it crashes. But there is no indication of what to do if you need to interrupt or cancel a running helper.

For example, if I have an XPC client that displays a 32-bit QuickTime movie, how do I get my 64-bit "parent" application to signal the XPC helper to cancel the job and clean up?

Also, what is the appropriate way for an XPC helper application to handle a parent that has "Quit"?

I currently use (NSXPCConnection) to complete on the parent app side:

  • (canceled) suspend
  • (canceled) invalid

They seem to be closing the connection. But I don't see any evidence that the helper app is paying attention.

Thanks in advance!

+3


source to share


1 answer


Your question doesn't seem to require proper handling of any helper failures. Instead, you feel like you just need a way to correctly communicate completion to the helper. If this is correct, please read for a solution. At least if you still need three years after the request ...

You haven't specified the language to use, so keep in mind that my examples are written in Swift.

Within your NSXPCConnection, you need to define the protocol that will be used to exchange information between the application and the helper. In this protocol, you can add a simple function with signature and content like this:

terminateHelper(withReply reply: (String) -> Void) {
    reply("Terminating BeKo Helper.")
    exit(0)
}

      

This function communicates the message string back to the main application using the provided closure, and then terminates itself with a system call exit

.



From the main application, you call this function like this:

if let helper = helperConnection.remoteObjectProxyWithErrorHandler({ (error) in
    let e = error as NSError
    print("Helper communication failed. Remote proxy error \(e.code): \(e.localizedDescription) \(e.localizedRecoverySuggestion ?? "---")")
}) as? HelperProtocol {
    helper.terminateHelper(withReply: { (replyString) in
        print(replyString)
    })
}

      


Please do not launchd

immediately restart the terminated helper application, even though it did not crash but was gracefully terminated. However, this ensures that the helper returns to an initialized state, stopping all previous auxiliary processing.

If you pause or cancel the way you asked your question, you will cancel the XPC connection. But no connection invalidation suspension will send any message to the helper. The helper himself will simply see that the connection is suspended or invalid, without knowing the reason.

Hopefully this gives you at least an idea of ​​how to proceed with your problem.

0


source







All Articles