One Logo Pool Ball
RealityKit · IOS API REFERENCE

MultipeerConnectivityService

class · iOS 13.0+ · SDK 27.1

class MultipeerConnectivityService

A service that provides scene synchronization among all peers in a multipeer connectivity session. RealityKit uses this class to automatically sync scenes with other connected devices running the same app. It leverages the <doc://com.apple.documentation/documentation/multipeerconnectivity> framework to automatically keep the scenes of all connected devices synchronized. To sync a RealityKit scene, create a ``MultipeerConnectivityService`` object initialized with an <doc://com.apple.documentation/documentation/multipeerconnectivity/mcsession> and assign it to your scene’s ``Scene/synchronizationService`` property. ```swift let peerID = MCPeerID(displayName: UIDevice.current.name) let session = MCSession(peer: peerID, securityIdentity: nil, encryptionPreference: .required) arView.scene.synchronizationService = try? MultipeerConnectivityService(session: self.session) ``` For more information on browsing for, and connecting to, other devices, see <doc://com.apple.documentation/documentation/multipeerconnectivity>.

Members (8)

method · iOS 13.0+

setHandshake

TypeScript
setHandshake(count: number, timeoutMs: number): void
Swift declaration
func setHandshake(count: UInt32, timeoutMs: UInt32)

Configures handshake and timeout settings. When RealityKit begins syncing with a connected device, it sends that device a special message, called a _handshake packet_, over the network and waits for a response. Once it receives the correct response, it begins syncing the local RealityKit scene with the other connected app. By default, RealityKit sends at most two handshake packets to a peer and waits up to 25,000 ms (25 seconds) for the peer to respond before giving up and disconnecting. Call this method to change the timeout or the number of handshake packets to send. - Parameters: - count: The maximum number of handshake packets to send to peers. - timeoutMs: The maximum amount of time to wait for peers to respond to handshake packets.

method · iOS 13.0+

giveOwnership

TypeScript
giveOwnership(entity: _RealityFoundation_Entity, peer: Implements<_RealityFoundation_SynchronizationPeerID> | SDKHandle): Promise<boolean>
Swift declaration
@MainActor @preconcurrency func giveOwnership(of entity: Entity, toPeer peer: any SynchronizationPeerID) -> Bool

Transfers ownership of the given entity to the named network device. - Parameters: - entity: The entity whose ownership is transferred. - peer: The networked device receiving ownership. - Returns: A Boolean that’s `true` if the ownership transfer succeeds.

method · iOS 13.0+

owner

TypeScript
owner(entity: _RealityFoundation_Entity): Promise<(SDKHandle) | null>
Swift declaration
@MainActor @preconcurrency func owner(of entity: Entity) -> (any SynchronizationPeerID)?

Gets the device that owns a given entity. - Parameters: - entity: The entity for which you want the owner. - Returns: The networked device that owns the entity.

method · iOS 13.0+

entity

TypeScript
entity(identifier: number): Promise<(_RealityFoundation_Entity) | null>
Swift declaration
@MainActor @preconcurrency func entity(for identifier: MultipeerConnectivityService.Identifier) -> Entity?

Gets the entity with the given identifier. - Parameters: - identifier: The identifier. - Returns: The entity with the corresponding identifier.

init · iOS 13.0+

init

TypeScript
static init(session: _MultipeerConnectivity_MCSession): MultipeerConnectivityService
Swift declaration
init(session: MCSession) throws

Creates a new connectivity service. - Parameters: - session: The multipeer connectivity session used to connect peers.

get · iOS 13.0+

session

TypeScript
get session(): _MultipeerConnectivity_MCSession
Swift declaration
final let session: MCSession

The multipeer connectivity session used by the service.

method · iOS 13.0+

stopSync

TypeScript
stopSync(): void
Swift declaration
func stopSync()

Stops multipeer synchronization. Call this method to stop multipeer syncing with connected peers. To resume syncing after calling this method, call ``MultipeerConnectivityService/startSync()``.

method · iOS 13.0+

startSync

TypeScript
startSync(): void
Swift declaration
func startSync()

Begins multipeer synchronization. Call this method to restart multipeer syncing with connected peers after calling ``MultipeerConnectivityService/stopSync()``. You don’t need to call this method to begin syncing. RealityKit calls this method automatically when you assign a ``MultipeerConnectivityService`` to a ``Scene``.

Skipped declarations

No declarations were skipped in this snapshot.

All RealityKit types →