app开发者平台在数字化时代的重要性与发展趋势解析
833
2022-11-03
MultipeerKit :网内(通过 Wi-Fi,蓝牙)多设备点对点/多点通讯框架
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.
Sample app
Check the example folder for a sample implementation.
Usage
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.
// Create a transceiver (make sure you store it somewhere, like a property)let transceiver = MultipeerTransceiver()// Start it up!transceiver.resume()// Configure message receiverstransceiver.receive(SomeCodableThing.self) { payload in print("Got my thing! \(payload)")}// Broadcast message to peerslet payload = SomeEncodableThing()transceiver.broadcast(payload)
For more information on how to use MultipeerKit, check the Swift files in the Public API folder, I tried my best to document all important aspects of using the framework.
Integrating
MultipeerKit is a Swift package, to use it in your project, add this to your Package.swift file:
let package = Package( ... dependencies: [ .package(url: "https://github.com/insidegui/MultipeerKit.git", from: "0.1.0") ], ...)
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~