Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Bridging Apps with iOS Multipeer Connectivity Zamzam Farzamipooya Engineering Manager @ Veo @zamzampooya SwiftCraft 2024

Slide 3

Slide 3 text

What Is Multipeer Connectivity Support peer-to-peer connectivity and the discovery of nearby devices In iOS, the framework uses infrastructure Wi-Fi networks, peer-to-peer Wi-Fi, and Bluetooth personal area networks for the underlying transport. In macOS and tvOS, it uses infrastructure Wi-Fi, peer-to-peer Wi-Fi, and Ethernet.

Slide 4

Slide 4 text

Why Multipeer Connectivity? Decentralized Network No Internet Required Ease of Use Adaptive Connectivity Versatility

Slide 5

Slide 5 text

Why Not? Limited Range Performance Variability Complex Network Management Compatibility

Slide 6

Slide 6 text

What It Can Be Used For Collaborative tools Messaging Education Location based Social Networking Gaming!

Slide 7

Slide 7 text

Multipeer Connectivity Framework Key Concepts Session objects (MCSession) support communication between connected peer devices. Advertiser objects (MCNearbyServiceAdvertiser) tell nearby peers that your app is willing to join sessions of a specified type. Browser objects (MCNearbyServiceBrowser) let your app search programmatically for nearby devices with apps that support sessions of a particular type. Peer IDs (MCPeerID) uniquely identify an app running on a device to nearby peers.

Slide 8

Slide 8 text

How It Works Advertiser Browser It is findable It can find other advertisers Finds an Advertiser Sends Invite Receives Invite Accepts Invite Connected Session They can send and receive data

Slide 9

Slide 9 text

Tic-Tac-Toe Find nearby players Connect to one opponent Play!

Slide 10

Slide 10 text

Setting Up Info.plist Getting permissions from the user Privacy — Local Network Usage Description Also we need to add the following to Info.plist

Slide 11

Slide 11 text

MCManager ServiceType -> The same name as in the info.plist Advertiser Browser Session Players

Slide 12

Slide 12 text

Player A model to keep track of players MCPeerID Name MCSessionState PlayerType

Slide 13

Slide 13 text

Setting Up The Environment PeerID CurrentPlayer Session Advertiser Browser Their delegates

Slide 14

Slide 14 text

Starting The Sessions

Slide 15

Slide 15 text

Starting The Sessions .addPlayer .findingPlayers .play

Slide 16

Slide 16 text

Add Player .addPlayer .findingPlayers We need to have a list of all nearby peers

Slide 17

Slide 17 text

Informs us when a peer is found Informs us when a peer is lost MCNearbyServiceBrowserDelegate

Slide 18

Slide 18 text

Showing Nearby Peers Using availablePlayers list to show nearby peers Inviting peers to join our session

Slide 19

Slide 19 text

Incoming invitation request Automatically connect Or show and alert for connection request MCNearbyServiceAdvertiserDelegate

Slide 20

Slide 20 text

MCSessionDelegate Called when the state of a nearby peer changes

Slide 21

Slide 21 text

When Connected From .addPlayer or .findingPlayers To .play

Slide 22

Slide 22 text

MCSessionDelegate Data Handling - Sending https://developer.apple.com/documentation/multipeerconnectivity/mcsession

Slide 23

Slide 23 text

Send playerType on Connection The starter is X and the other is O

Slide 24

Slide 24 text

MCSessionDelegate Data Handling - Message

Slide 25

Slide 25 text

MCSessionDelegate Data Handling - Receiving

Slide 26

Slide 26 text

MCSessionDelegate Data Handling - Decoding

Slide 27

Slide 27 text

Game Logic @1TheSwiftGuy

Slide 28

Slide 28 text

Sending Game Logic

Slide 29

Slide 29 text

Demo Time! Let’s play

Slide 30

Slide 30 text

Challenges Background mode and reestablishing the connection Debugging Unexpected behaviour Poor

Slide 31

Slide 31 text

Future of Multipeer Connectivity Cross-Platform Compatibility Enhanced Performance and Reliability Integration with IoT and Smart Devices Better support for background mode

Slide 32

Slide 32 text

@zamzampooya #WomenLifeFreedom Thank You