با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
پس از برقراری ارتباط بین دستگاهها، میتوانید تبادل داده را آغاز کنید. داده های مبادله شده می توانند به شکل یک آرایه بایتی ساده مانند یک پیام متنی کوتاه باشند. یک فایل، مانند عکس یا ویدیو؛ یا یک جریان، مانند پخش جریانی صدا از میکروفون دستگاه.
داده ها را می توان با استفاده از روش های مثال مدیر اتصال زیر ارسال کرد:
send(_:to:)
startStream(_:to:)
sendResource(at:withName:to:)
هنگام دریافت داده ها می توان از روش های واگذاری مدیر اتصال زیر استفاده کرد.
سویفت
extensionExample:ConnectionManagerDelegate{funcconnectionManager(_connectionManager:ConnectionManager,didReceivedata:Data,withIDpayloadID:PayloadID,fromendpointID:EndpointID){// A simple byte payload has been received. This will always include the full data.}funcconnectionManager(_connectionManager:ConnectionManager,didReceivestream:InputStream,withIDpayloadID:PayloadID,fromendpointID:EndpointID,cancellationTokentoken:CancellationToken){// We have received a readable stream.}funcconnectionManager(_connectionManager:ConnectionManager,didStartReceivingResourceWithIDpayloadID:PayloadID,fromendpointID:EndpointID,atlocalURL:URL,withNamename:String,cancellationTokentoken:CancellationToken){// We have started receiving a file. We will receive a separate transfer update// event when complete.}funcconnectionManager(_connectionManager:ConnectionManager,didReceiveTransferUpdateupdate:TransferUpdate,fromendpointID:EndpointID,forPayloadpayloadID:PayloadID){// A success, failure, cancelation or progress update.}}
تاریخ آخرین بهروزرسانی 2025-08-13 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-13 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eAfter establishing connections between devices, data exchange can commence, encompassing various formats like byte arrays, files, or streams.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eConnectionManager\u003c/code\u003e offers methods such as \u003ccode\u003esend(_:to:)\u003c/code\u003e, \u003ccode\u003estartStream(_:to:)\u003c/code\u003e, and \u003ccode\u003esendResource(at:withName:to:)\u003c/code\u003e for initiating data transmission.\u003c/p\u003e\n"],["\u003cp\u003eTo receive data, implement the \u003ccode\u003eConnectionManagerDelegate\u003c/code\u003e protocol, providing methods to handle byte payloads, streams, file transfers, and transfer updates.\u003c/p\u003e\n"],["\u003cp\u003eWhile payloads of the same type maintain their sending order upon arrival, there's no guarantee of order preservation across different payload types.\u003c/p\u003e\n"]]],[],null,["# Exchange data\n\nOnce connections are established between devices, you can start exchanging data.\nThe exchanged data can take the form of a simple byte array, such as a short\ntext message; a file, such as a photo or video; or a stream, such as the audio\nstream from the device's microphone.\n\nData can be sent using the following connection manager instance methods:\n\n- `send(_:to:)`\n- `startStream(_:to:)`\n- `sendResource(at:withName:to:)`\n\nThe following connection manager delegate methods can be utilized when receiving\ndata. \n\n### Swift\n\n extension Example: ConnectionManagerDelegate {\n func connectionManager(\n _ connectionManager: ConnectionManager, didReceive data: Data,\n withID payloadID: PayloadID, from endpointID: EndpointID) {\n // A simple byte payload has been received. This will always include the full data.\n }\n\n func connectionManager(\n _ connectionManager: ConnectionManager, didReceive stream: InputStream,\n withID payloadID: PayloadID, from endpointID: EndpointID,\n cancellationToken token: CancellationToken) {\n // We have received a readable stream.\n }\n\n func connectionManager(\n _ connectionManager: ConnectionManager,\n didStartReceivingResourceWithID payloadID: PayloadID,\n from endpointID: EndpointID, at localURL: URL,\n withName name: String, cancellationToken token: CancellationToken) {\n // We have started receiving a file. We will receive a separate transfer update\n // event when complete.\n }\n\n func connectionManager(\n _ connectionManager: ConnectionManager,\n didReceiveTransferUpdate update: TransferUpdate,\n from endpointID: EndpointID, forPayload payloadID: PayloadID) {\n // A success, failure, cancelation or progress update.\n }\n }\n\n| **Note:** Payloads of the same type are guaranteed to arrive in the order they were sent, but there is no guarantee of preserving the ordering amongst payloads of different types. For example, if a sender sends a file followed by a bytes payload, the receiver could get the bytes payload first, followed by the file."]]