In Windows I can post custom message to another process and inform it to do an action like:

PostMessage(WindowOfAnyProcess, WM_CUSTOM_MESSAGE, param1, param2)

What is the alternative on Mac OS? Does Carbon Events help me? How? Thankyou.

有帮助吗?

解决方案

Assuming that both of the processes are yours, you can use NSDistributedNotificationCenter to send notifications and data to each process.

To do this do something like:

[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"HelloFromProcessOne" object:nil]

If you want to include data you can use:

[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"HelloFromProcessOne" object:nil userInfo:[NSDictionary dictionaryWithObject:@"some info here" forKey:@"data"]]

A note should be added that: Sandboxed apps can send notifications only if they do not contain a dictionary. If the sending application is in an App Sandbox, notificationInfo must be nil. This means that you won't be able to provide information with the notification if you intend on targeting the Mac AppStore.

To make the application receive the notifications do something like:

[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(someNotificationUpdate:) name:@"HelloFromProcessOne" object:nil]

someNotificationUpdate: would be declared like:

- (void)someNotificationUpdate:(NSNotification *)note;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top