나는 사용자가 창에 버튼을 밀어 때 자체에 NSNotification을 보내는 작업 응용 프로그램을 (엑스 코드는 PyObjC 사용)이 있습니다NSNotifications X
from Foundation import *
from AppKit import *
import objc
class SpeakAppDelegate(NSObject):
def applicationDidFinishLaunching_(self, sender):
NSLog("Application really did finish launching.")
nc = NSNotificationCenter.defaultCenter()
nc.addObserver_selector_name_object_(
self, "mycallback:", 'love_note', None)
#self, "mycallback:", None, None)
@objc.signature('[email protected]:@8')
def mycallback_(self,note):
print 'note'
print note.description()
@objc.IBAction
def button_(self,sender):
print sender, 'button'
nc = NSNotificationCenter.defaultCenter()
nc.postNotificationName_object_userInfo_(
'love_note', None, {'path':'xyz'})
(A 세부 사항 : 서명은 아마도 정확하지는 않지만 작동합니다).
실행 상태로 둡니다. 지금은 예를 들어, 다른 응용 프로그램에서이 응용 프로그램에 같은 통지를 보내는 방법을 파악하려는 :
// gcc tell.m -o test -framework Foundation
#import <Foundation/Foundation.h>
int main() {
NSNotificationCenter *nc;
nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:@"love_note"
object:nil
userInfo:nil ];
return 0;
}
내가 처음 App에서 선을 유엔의 주석이라면 내가 다른 통지를 많이 얻을 것을 알 수 ,하지만 그들은 모두 내 앱과 관련된 이벤트에서 온 것입니다. 나는 외부에서 아무것도 듣지 못한다. 프로세스간에 알림을 보내려면 어떻게해야합니까? 그런 다음 명령 줄에서 알림을 보낼 수있는 방법이 있습니까? 감사.
업데이트 : 위의 NSDistributedNotificationCenter를 대체하기 만하면이 예제가 작동합니다.
감사합니다. 두 종류의 센터 사이의 구분은 나를 벗어났습니다. – telliott99
정말 알림 유형에 따라 다릅니다. 예를 들어 iTunes는 노래 재생을 시작하거나 중지 할 때마다 알림을 보냅니다. 이러한 알림을 수신하는 응용 프로그램을 작성할 수 있습니다. 목표가 리모컨을 갖는 것이 더 많은 경우, 일종의 직접 통신 (예 : 분산 객체를 통한)이 더 적절합니다. –
+1 분산 알림 용. 그들은 안전하지 못하지만, 기본적인 의사 소통을 위해 그들은 꽤 뇌사 상태입니다. –