Skip to content

Commit

Permalink
Added documentation catalog, updated Package.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
insidegui committed Jun 18, 2021
1 parent 814c3c0 commit 2f457b0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.1
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
44 changes: 44 additions & 0 deletions Sources/MultipeerKit/Documentation.docc/Documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ``MultipeerKit``

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.

## Overview

MultipeerKit is an abstraction on top of the MultipeerConnectivity framework, which enables peer-to-peer communication of Apple devices over WiFi.

With MultipeerKit, you can exchange messages between Apple devices running your app, the message can be anything that implements the `Codable` protocol.

## Getting Started

### Info.plist Requirements

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.

The keys are `Privacy - Local Network Usage Description` (`NSLocalNetworkUsageDescription`) and `Bonjour services` (`NSBonjourServices`).

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.

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

### Sending and Receiving Messages

The main class in this library is ``MultipeerTransceiver``, which does both the sending and receiving aspects of the multipeer communication.

MultipeerKit can transmit and receive anything that conforms to the `Codable` protocol, which makes it easy for you to define your own message types.

```swift
// Create a transceiver (make sure you store it somewhere, like a property)
let transceiver = MultipeerTransceiver()

// Start it up!
transceiver.resume()

// Configure message receivers
transceiver.receive(SomeCodableThing.self) { payload, sender in
print("Got my thing from \(sender.name)! \(payload)")
}

// Broadcast message to peers
let payload = SomeEncodableThing()
transceiver.broadcast(payload)
```
2 changes: 2 additions & 0 deletions Sources/MultipeerKit/Internal API/MultipeerConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Foundation
import MultipeerConnectivity
import os.log

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

public struct MultipeerError: LocalizedError {
Expand Down

0 comments on commit 2f457b0

Please sign in to comment.