Skip to content

Commit 2f457b0

Browse files
committed
Added documentation catalog, updated Package.swift
1 parent 814c3c0 commit 2f457b0

3 files changed

Lines changed: 47 additions & 1 deletion

File tree

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.1
1+
// swift-tools-version:5.5
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# ``MultipeerKit``
2+
3+
A high-level abstraction built on top of the MultipeerConnectivity framework, which allows iOS, macOS and tvOS devices to exchange data between them over Wi-Fi networks, peer-to-peer Wi-Fi, and Bluetooth.
4+
5+
## Overview
6+
7+
MultipeerKit is an abstraction on top of the MultipeerConnectivity framework, which enables peer-to-peer communication of Apple devices over WiFi.
8+
9+
With MultipeerKit, you can exchange messages between Apple devices running your app, the message can be anything that implements the `Codable` protocol.
10+
11+
## Getting Started
12+
13+
### Info.plist Requirements
14+
15+
Starting with iOS 14, you will have to include two keys in your app's Info.plist file in order for MultipeerKit to work properly.
16+
17+
The keys are `Privacy - Local Network Usage Description` (`NSLocalNetworkUsageDescription`) and `Bonjour services` (`NSBonjourServices`).
18+
19+
For the privacy key, include a human-readable description of what benefit the user gets by allowing your app to access devices on the local network.
20+
21+
The Bonjour services key is an array of service types that your app will browse for. For MultipeerKit, the entry should be in the format `_servicename._tcp`, where `servicename` is the `serviceType` you've set in your `MultipeerConfiguration`. If you're using the default configuration, the value of this key should be `_MKSVC._tcp`.
22+
23+
### Sending and Receiving Messages
24+
25+
The main class in this library is ``MultipeerTransceiver``, which does both the sending and receiving aspects of the multipeer communication.
26+
27+
MultipeerKit can transmit and receive anything that conforms to the `Codable` protocol, which makes it easy for you to define your own message types.
28+
29+
```swift
30+
// Create a transceiver (make sure you store it somewhere, like a property)
31+
let transceiver = MultipeerTransceiver()
32+
33+
// Start it up!
34+
transceiver.resume()
35+
36+
// Configure message receivers
37+
transceiver.receive(SomeCodableThing.self) { payload, sender in
38+
print("Got my thing from \(sender.name)! \(payload)")
39+
}
40+
41+
// Broadcast message to peers
42+
let payload = SomeEncodableThing()
43+
transceiver.broadcast(payload)
44+
```

Sources/MultipeerKit/Internal API/MultipeerConnection.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import Foundation
22
import MultipeerConnectivity
33
import os.log
44

5+
/// The completion handler called when the remote peer responds to a manual invite initiated
6+
/// by calling ``MultipeerTransceiver/invite(_:with:timeout:completion:)``.
57
public typealias InvitationCompletionHandler = (_ result: Result<Peer, Error>) -> Void
68

79
public struct MultipeerError: LocalizedError {

0 commit comments

Comments
 (0)