KYNearbyService

1.1.0

A service for nearby discovery and communication.
Kjuly/KYNearbyService

What's New

1.1.0

2023-12-29T03:13:34Z

KYNearbyService

A service for nearby discovery and communication.

macOS iOS SwiftPM

iPhone Preview Mac Preview

Installation

See the following subsections for details on the different installation methods.

Usage

  1. 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>
  1. Use the existing KYNearbyConnectionView or setup your own one to provide as the connection view. A demo project is available under "/KYNearbyServiceDemo".

  2. 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)

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

Last updated: Thu Apr 18 2024 06:48:55 GMT-0900 (Hawaii-Aleutian Daylight Time)