How to kill helper app of a sandboxed application that is not responding?

The main app communicates with the helper app periodically, but how to handle situations where the helper app gets stuck and stops responding to messages?

[NSRunningApplication forceTerminate] would have worked, but it always returns NO when app sandbox is enabled, even if the app being terminated is part of the same app group.

Answered by DTS Engineer in 642654022

Isn't this the correct way to launch the helper app?

That kinda depends. If it’s an app with a GUI then definitely yes. However, the absence of a GUI, and the fact that it periodically goes unresponsive, makes me suspect that it’s not actually an app but a command-line tool packaged to look like an app. In that case, launching it with NSTask (Process in Swift) might make more sense. When you do that it becomes your child process and the sandbox will let you send signals to it.

And yes, it’ll keep running after your app quits.

ps If you have code that continues running after the main app quits, be aware of clause 2.4.5(iii) of the App Store Review Guidelines.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"

-[NSRunningApplication forceTerminate] would have worked, but it
always returns NO when app sandbox is enabled

Right. That method sends a UNIX signal and that’s blocked by the App Sandbox.

How is your helper app launched? And is it an app, with a GUI and so on? Or something else?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Yes, it is an application bundle (.app) but does not have a GUI. It is launched by the main application using [[NSWorkspace sharedWorkspace] launchApplicationAtURL:....].
Why do you launch it that way? What’s the lifecycle of this helper app?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Isn't this the correct way to launch the helper app? The main app launches the helper app when it needs to perform some background processing and it can outlive the main application.

The main app launches the helper app when it needs to perform some background processing and it can outlive the main application.

If the main app isn't running, how is it supposed to kill the helper?

the helper app gets stuck and stops responding to messages

Until you correct this problem, a solution is impossible.

If your helper app is able to reliably and asynchronously monitor some external source for commands, then there are many ways to control it. Some system methods might be blocked by the sandbox, but there are still plenty more to choose from. If your requirement is that the helper stays live while the main comes and goes, then that will further limit your options, but there are still ways to do it. Maybe try a named FIFO. Or you can listen on a network port for commands. You will have to explain any networking to App Review.
Accepted Answer

Isn't this the correct way to launch the helper app?

That kinda depends. If it’s an app with a GUI then definitely yes. However, the absence of a GUI, and the fact that it periodically goes unresponsive, makes me suspect that it’s not actually an app but a command-line tool packaged to look like an app. In that case, launching it with NSTask (Process in Swift) might make more sense. When you do that it becomes your child process and the sandbox will let you send signals to it.

And yes, it’ll keep running after your app quits.

ps If you have code that continues running after the main app quits, be aware of clause 2.4.5(iii) of the App Store Review Guidelines.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
How to kill helper app of a sandboxed application that is not responding?
 
 
Q