• Stars
    star
    224
  • Rank 171,401 (Top 4 %)
  • Language
    Swift
  • License
    MIT License
  • Created about 6 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ“±πŸ“² A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices

Build Status CocoaPods Version Status Carthage compatible doccov iOS MacOS tvOS Swift MIT License

A wrapper for Apple's MultipeerConnectivity framework for offline data transmission between Apple devices. This framework makes it easy to automatically connect to multiple nearby devices and share information using either bluetooth or wifi radios.

  1. Features
  2. Integration
  3. Usage
  4. Example
  5. License
  6. Authors

Features

  • Supports iOS/macOS/tvOS
  • Auto Connection
  • Auto Invitations/Advertising
  • Send/Receive data via MultipeerConnectivity Framework
  • Specify data types for easy handling

Integration

CocoaPods

You can use CocoaPods to install MultiPeer by adding it to your Podfile:

pod 'MultiPeer'

Carthage

You can use Carthage to install MultiPeer by adding it to your Cartfile:

github "dingwilson/MultiPeer"

Swift Package Manager

For SPM, add the following to your package dependencies:

.package(url: "https://github.com/dingwilson/MultiPeer.git", .upToNextMinor(from: "0.0.0"))

Usage

To get started, import MultiPeer.

import MultiPeer

Then, simply initialize MultiPeer with the name of your session (serviceType). There are two modes of connections (advertiser and browser). To utilize both, simply use .autoConnect().

MultiPeer.instance.initialize(serviceType: "demo-app")
MultiPeer.instance.autoConnect()

Any data transmitted by MultiPeer will always be accompanied by a numerical "type", to ensure other peers know what kind of data is being received, and how to properly process it. You can manage this by creating a UInt32 enum, as shown below:

enum DataType: UInt32 {
  case string = 1
  case image = 2
  // ...
}

To send data, simply use the .send(object: type:) function:

MultiPeer.instance.send(object: "Hello World!", type: DataType.string.rawValue)

To receive data, we must conform to the MultiPeerDelegate protocol:

func multiPeer(didReceiveData data: Data, ofType type: UInt32, from peerID: MCPeerID) {
  switch type {
    case DataType.string.rawValue:
      let string = data.convert() as! String
      // do something with the received string
      break
      		
    case DataType.image.rawValue:
      let image = UIImage(data: data)
      // do something with the received UIImage
      break
      		
    default:
      break
  }
}

func multiPeer(connectedDevicesChanged devices: [String]) {
}

Ensure that you set the MultiPeer delegate.

MultiPeer.instance.delegate = self

Finally you'll need to enable incoming / outgoing connections in your entitlements.

Congratulations! You have successfully sent data using MultiPeer! For more detailed information (including details of other functions), please see the docs.

Example

For an example app using MultiPeer, checkout MultiPeer_Sample.

License

MultiPeer is released under an MIT License. See LICENSE for details.

Authors

Project heavily inspired by Apple-Signal.

More Repositories

1

SwiftVideoBackground

πŸ“Ή Framework to Play a Video in the Background of any UIView
Swift
343
star
2

RandomUserSwift

πŸ‘€ Framework to Generate Random Users - An Unofficial Swift SDK for randomuser.me
Swift
96
star
3

Hackathon-Packing-List

πŸ“‹ Hackathon Packing List - A Handy Guide
18
star
4

MultiPeer_Sample

Sample application for MultiPeer Framework
Swift
16
star
5

CleverCalorie

🍴CodeRED Hackathon Project - iOS Health App. Point your camera at a plate of food and find out the nutritional information in realtime.
Objective-C
8
star
6

ProxyChat

πŸ’¬TAMUHack Hackathon Project - Offline Swift iOS Social Communicator
Swift
4
star
7

BackTrack

πŸŽ™IncubateX Hackathon Project - iOS Passive Audio Recorder w/ IBM Watson STT and AlchemyAPI NLP Integrations
Swift
4
star
8

SousChef

πŸ‘¨πŸ»β€πŸ³ HackUTD Hackathon Project - iOS Swift personal assistant for finding and reading recipes
Swift
3
star
9

DivBin

iOS Swift app using object recognition and machine learning to classify objects as recyclable, compostable, donatable, or trash
Swift
2
star
10

Seek

πŸ”Ž PennApps Hackathon Project - iOS app to search YouTube via object recognition and speech-to-text
Swift
2
star
11

Motivation.safariextension

New Safari tab page showing your age
JavaScript
2
star
12

todoist-scripts

Python
2
star
13

CTF-AI

Java
2
star
14

dotfiles

πŸ”§ My dotfiles and system config
Shell
2
star
15

BreathEZ

πŸ’Š SASEHack Hackathon Project - iOS App to regulate breathing for those who suffer from panic or anxiety attacks
Swift
1
star
16

world-mapkit-geojson

Swift
1
star
17

FlightBuddy

Swift
1
star
18

Bridgit

πŸ”Ž Facebook Global Hackathon Finale Hackathon Project - Crowd-Sourced License Plate Detection via OCR
Swift
1
star
19

Database-Project-Bonus

Swift
1
star
20

FitBuddy

Swift
1
star