GithubHelp home page GithubHelp logo

kjuly / kynearbyservice Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 2.0 79 KB

A service for nearby discovery and communication.

License: MIT License

Objective-C 0.45% Swift 98.66% Ruby 0.89%
airdrop bluetooth bonjour ios local-network mac-catalyst macos multipeer-connectivity swift swift-ui

kynearbyservice's Introduction

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.