kjuly/kynearbyservice
A service for nearby discovery and communication.
Installation
See the following subsections for details on the different installation methods.
Usage
- Setup KYNearbyService with your service type.
KYNearbyService.setup(with: KYNearbyServiceConfiguration(serviceType: "your-service")[!IMPORTANT] Make sure you've provided NSBonjourServices in your *.plist file.
<key>NSBonjourServices</key> <array> <string>_your-service._tcp</string> <string>_your-service._udp</string> </array>
- Use the existing
KYNearbyConnectionViewor setup your own one to provide as the connection view. A demo project is available under "/KYNearbyServiceDemo".
- Observe notifications (
Notification.Name.KYNearbyService.*) to handle events.
| Notification | When | Notes | --- | --- | --- | didUpdatePeerDisplayName | The user changed the display name | The name is provided as note.object. | shouldSendResource | The user pressed the "SEND" button | The target peer item (KYNearbyPeerModel instance) is provided as note.object. And you can use KYNearbyService.sendResource(for:at:withName:completion:) to send the resource to the target peer. | didStartReceivingResource | The service start receiving resource | | didReceiveResource | The service did receive resource | The details are available in note.userInfo. And the file will be saved to KYNearbyServiceDefaultFolderURL.archives by default. You can config the destination folder url by KYNearbyServiceConfiguration.
e.g.
NotificationCenter.default.addObserver(
self,
selector: #selector(_handleKYNearbyServiceShouldSendResourceNotification),
name: .KYNearbyService.shouldSendResource,
object: nil)All Peer Status Preview
<div align="center"> <img src="https://raw.githubusercontent.com/Kjuly/preview/main/KYNearbyService/AllPeerStatus.png" alt="iPhone Preview" height="360" /> <img src="https://raw.githubusercontent.com/Kjuly/preview/main/KYNearbyService/AllPeerStatusLandscape.png" alt="iPhone Preview" height="260" /> </div>
You can go to the demo project's KYNearbyServiceDemoApp.init(), and switch .none to allPeerStatuses to get a list of all peer statuses:
KYNearbyService.shared.debug_populateMockPeers(for: .allPeerStatuses)Package Metadata
Repository: kjuly/kynearbyservice
Default branch: main
README: README.md