카카오의 대답은 내 목표를 달성하기 위해 영감을주었습니다. 다음은 내 코드 (ARC)입니다.
- (BOOL)checkAppDuplicateAndBringToFrontWithBundle:(NSBundle *)bundle
{
NSRunningApplication *app;
NSArray *appArray;
NSUInteger tmp;
pid_t selfPid;
BOOL ret = NO;
selfPid = [[NSRunningApplication currentApplication] processIdentifier];
appArray = [NSRunningApplication runningApplicationsWithBundleIdentifier:[bundle bundleIdentifier]];
for (tmp = 0; tmp < [appArray count]; tmp++)
{
app = [appArray objectAtIndex:tmp];
if ([app processIdentifier] == selfPid)
{
/* do nothing */
}
else
{
[[NSWorkspace sharedWorkspace] launchApplication:[[app bundleURL] path]];
ret = YES;
}
}
return ret;
}
번들 식별자로 앱 중복을 확인합니다. 번들이 복제되면 다른 모든 응용 프로그램이 앞에오고 YES를 반환합니다. YES를 받으면 응용 프로그램을 종료 할 수 있습니다.
그러나 카카오가 중요한 도움을 주었기 때문에 나는이 질문의 명성을 줬다. 고맙습니다!
마하 포트를 등록하십시오. 나는 얼마 전에 이것에 대한 요지를 썼다. https://gist.github.com/CodaFi/5639819 – CodaFi
OS X가 실제로 시나리오 1에서 두 번째 인스턴스를 시작한다는 사실에 놀랐다. – cacau