I am using the openApplicationAtURL:(NSURL *)applicationURL configuration:(NSWorkspaceOpenConfiguration *)configuration completionHandler:(void (^ _Nullable)(NSRunningApplication *_Nullable app, NSError *_Nullable error))completionHandler
function to open the application itself on macOS Ventura.
I need to restart the software itself before it exits. So I call the openApplicationAtURL function to reopen it. But it failed.
In the same code, I can successfully open any other software(As soon as I change the name of the software), but it can not open the software itself.
Is there any way to resolve it?
Sample code:
NSBundle* bundle = NSBundle.mainBundle;
NSWorkspace* workspace = NSWorkspace.sharedWorkspace;
NSWorkspaceOpenConfiguration* configuration = [NSWorkspaceOpenConfiguration new];
NSDictionary* env = @{};
[configuration setEnvironment: env];
[configuration setPromptsUserIfNeeded: YES];
NSString* path = bundle.bundlePath;
[workspace openApplicationAtURL: [NSURL fileURLWithPath: path] configuration: configuration completionHandler:^(NSRunningApplication* app, NSError* error) {
if (error) {
NSLog(@"Failed to run the app: %@", error.localizedDescription);
}
}];