- (void)launchSoftWithBundleID:(NSString *)softPath
{
NSBundle *softBundle = [NSBundle bundleWithPath:softPath];
NSString *bundleID = [softBundle bundleIdentifier];
//运行程序
NSTask *softTask = [[NSTask alloc] init];
[softTask setLaunchPath:softPath];
[softTask launch];
//得到运行的程序,并置于最前面
NSArray *array = [NSRunningApplication runningApplicationsWithBundleIdentifier:bundleID];
if ([array count] > 0)
{
NSRunningApplication *runningApp = [array objectAtIndex:0];
[runningApp activateWithOptions:NSApplicationActivateIgnoringOtherApps];
}
}
Mac中启动另一个程序并将窗口置于最前面
最新推荐文章于 2025-11-04 12:59:30 发布
本文介绍了一种通过NSBundle和NSTask来启动指定路径下应用程序的方法。此外,还展示了如何通过NSRunningApplication将启动的应用置于最前。此技术适用于需要在后台启动其他应用并控制其窗口显示的场景。
2541

被折叠的 条评论
为什么被折叠?



