KYNearbyService

1.2.0

A service for nearby discovery and communication.
Kjuly/KYNearbyService

What's New

1.2.0

2024-06-20T12:24:06Z

KYNearbyService

A service for nearby discovery and communication.


macOS iOS
SPM CocoaPods Carthage

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)

All Peer Status Preview

iPhone Preview iPhone Preview

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)

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

Last updated: Mon Oct 28 2024 19:05:03 GMT-0900 (Hawaii-Aleutian Daylight Time)