Xcode Launch application and brint to front NSWorkspace
I have the following code to la开发者_如何学编程unch Address Book, now that works well, but is there a way I could launch this infront of the running application?
[[NSWorkspace sharedWorkspace] openFile:@"/Applications/Address Book.app" withApplication:nil];
Try the NSWorkspace method:
- (NSRunningApplication *)launchApplicationAtURL:(NSURL *)url options:(NSWorkspaceLaunchOptions)options configuration:(NSDictionary *)configuration error:(NSError **)error
Also note you should use URLForApplicationWithBundleIdentifier:
rather than a fixed path. This will work even if Address Book.app is moved in a future version of OS X, or the user moves it to a different folder.
You could even use [[NSWorkspace sharedWorkspace] launchApplication: @"Address Book"]
.
精彩评论