본문 바로가기

프로그래밍/MAC OS

communcation over XPC is asynchronous

반응형

https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingXPCServices.html

Designing an Interface

The NSXPCConnection API takes advantage of Objective-C protocols to define the programmatic interface between the calling application and the service. Any instance method that you want to call from the opposite side of a connection must be explicitly defined in a formal protocol. For example:


 @protocol FeedMeACookie
    - (void) feedMeACookie: (Cookie *)cookie;
 @end

 
Because communication over XPC is asynchronous, all methods in the protocol must have a return type of void. If you need to return data, you can define a reply block like this:

 @protocol FeedMeAWatermelon
    - (void) feedMeAWatermelon: (Watermelon *) watermelon
        reply: (void (^) (Rind *)) reply;
 @end
 
A method can have only one reply block. However, because connections are bidirectional, the XPC service helper can also reply by calling methods in the interface provided by the main application, if desired.

Each method must have a return type of void, and all parameters to methods or reply blocks must be either:
  • Arithmetic types (int, char, float, double, uint64_t, NSUInteger, and so on)
  • BOOL
  • C strings
  • C structures and arrays containing only the types listed above
  • Objective-C objects that implement the NSSecureCoding protocol.
NSXPCConnection API 는 호출하는 어플리케이션과 서비스간의 인터페이스를 프로그램적으로 정의한다. 호출하여 사용할 메소드는 프로토콜로 명시적으로 정의되어야 한다. 예를 들면 아래와 같다.

XPC를 통한 통신은 비동기적이기 때문에, 프로토콜의 모든 메소드는 void 를 반환하여야 한다. 반환되는 데이터가 필요할 때에는 reply 블록을 다음과 같이 정의할 수 있다.

메소드는 오직 하나의 reply 블록만 가질 수 있다. 

 

728x90