简体   繁体   中英

Reset / Re-initialize NSXPCConnection?

Sorry in advance if this is an obvious question or I demonstrate a total lack of knowledge here (which would be accurate).

  • OS: macOS (10.12+)
  • IDE: Xcode (11)
  • Using: Cococa + Objective-C

We're interacting with a C API. That API stores all sorts of session/environment information under the hood. There are specific API calls that require a total restart of the API, but the only way to accomplish that is fully shutting down the client application that invokes it (the API acts like a Singleton with no way to reinitialize itself).

My hope is that potentially wrapping the C API in an XPC Service would let me more gracefully shut down the service and restart it so I can avoid restarting the entire client application.

  1. Is that even remotely the right way of thinking about this need in Cocoa?
  2. If (if) it is, how would I go about doing that? I added a simple XPC Service to the existing app using File -> Add Target -> XPC Service. I can call into the C API and that all works using NSXPCConnection and hitting the appropriate service method from the app. I'm stumped on how I would potentially kill/reinitialize the XPC Service, though.
  3. Is there a different / better way to look at this?

Any direction / ideas / critiques most welcome

Thank you!

I think I got this to work with NSXPCConnection.

Following up on Kill XPC when parent app is still running I called what I could of the API's dispose-ish methods and then called exit(0) inside of a method in the the XPC connection.

So far, so good!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM