Exchange 데이터

기기 간 연결이 설정되면 데이터 교환을 시작할 수 있습니다. 교환되는 데이터는 짧은 문자 메시지나 사진, 동영상과 같은 파일, 기기 마이크의 오디오 스트림과 같은 스트림의 간단한 바이트 배열 형태일 수 있습니다.

다음 연결 관리자 인스턴스 메서드를 사용하여 데이터를 전송할 수 있습니다.

  • send(_:to:)
  • startStream(_:to:)
  • sendResource(at:withName:to:)

데이터를 수신할 때 다음 연결 관리자 위임 메서드를 활용할 수 있습니다.

Swift

extension Example: ConnectionManagerDelegate {
  func connectionManager(
    _ connectionManager: ConnectionManager, didReceive data: Data,
    withID payloadID: PayloadID, from endpointID: EndpointID) {
    // A simple byte payload has been received. This will always include the full data.
  }

  func connectionManager(
    _ connectionManager: ConnectionManager, didReceive stream: InputStream,
    withID payloadID: PayloadID, from endpointID: EndpointID,
    cancellationToken token: CancellationToken) {
    // We have received a readable stream.
  }

  func connectionManager(
    _ connectionManager: ConnectionManager,
    didStartReceivingResourceWithID payloadID: PayloadID,
    from endpointID: EndpointID, at localURL: URL,
    withName name: String, cancellationToken token: CancellationToken) {
    // We have started receiving a file. We will receive a separate transfer update
    // event when complete.
  }

  func connectionManager(
    _ connectionManager: ConnectionManager,
    didReceiveTransferUpdate update: TransferUpdate,
    from endpointID: EndpointID, forPayload payloadID: PayloadID) {
    // A success, failure, cancelation or progress update.
  }
}