5

Windowsでは、カスタムメッセージを別のプロセスに投稿し、次のようなアクションを実行するように通知できます。

PostMessage(WindowOfAnyProcess, WM_CUSTOM_MESSAGE, param1, param2)

Mac OSの代替手段は何ですか?カーボンイベントは役に立ちますか?どのように?ありがとうございました。

4

1 に答える 1

5

両方のプロセスが自分のものであると仮定すると、NSDistributedNotificationCenterを使用して通知とデータを各プロセスに送信できます。

これを行うには、次のようにします。

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

データを含めたい場合は、次を使用できます。

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

次の点に注意してください。 サンドボックス化されたアプリは、辞書が含まれていない場合にのみ通知を送信できます。送信アプリケーションがアプリ サンドボックスにある場合は、 であるnotificationInfo必要がありますnil。これは、Mac AppStore を対象とする場合、通知で情報を提供できないことを意味します。

アプリケーションに通知を受信させるには、次のようにします。

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

someNotificationUpdate:次のように宣言されます。

- (void)someNotificationUpdate:(NSNotification *)note;
于 2012-06-21T00:34:11.750 に答える