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>.
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.
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.
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.
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``.