NSWorkspace launchApplication: fails for the first time with root user

匿名 (未验证) 提交于 2019-12-03 01:00:01

问题:

I am trying to launch one of my apps(say app2) from another of my apps(say app1) on my Mac OS X 10.7.4. I am using the below code for the same:

[ [ NSWorkspace sharedWorkspace ] launchApplicationAtURL:[NSURL fileURLWithPath:appPath] options:NSWorkspaceLaunchDefault configuration:[NSDictionary dictionaryWithObject:[NSArray arrayWithObject: @"mode"] forKey:NSWorkspaceLaunchConfigurationArguments] error:&err]; 

This works fine except for the first time i.e. if we have a new machine, then the first attempt for launching the app2 from app1 fails when tried for the first time when logged in as root user but works fine subsequently.

Below is the error I get on dumping the NSError:

2012-11-05 07:47:48 +0000: The application “App2” could not be launched because a miscellaneous error occurred (OSStatus -10810).

Also, I get the below messages in "All Messages" in Console:

11/4/12 11:47:48.329 PM com.apple.launchd[1]: System: Bug: 12B19: launchd + 79534 [AEF41441-17BC-36E6-B1F8-57BADBDFEBCF]: 0x0

11/4/12 11:47:48.329 PM com.apple.launchd[1]: System: This API can only be used by a process running within an Aqua session.

11/4/12 11:47:48.329 PM App1[2405]: spawn_via_launchd() failed, errno=5 label=[0x0-0x57057].com.ak.app1 path=/var/root/Library/Caches/com.ak.app2/app2.app/Contents/MacOS/app2 flags=0

The strange think is that it only fails for the first attempt with root user.

回答1:

You appear to be attempting to launch an application from a non-UI process. This is no longer supported, as it uses LSOpenApplication internally, which does not support non-UI processes since Lion. Please see this discussion for more info



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!