• Stars
    star
    222
  • Rank 179,094 (Top 4 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 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
344
star
2

RandomUserSwift

๐Ÿ‘ค Framework to Generate Random Users - An Unofficial Swift SDK for randomuser.me
Swift
95
star
3

Hackathon-Packing-List

๐Ÿ“‹ Hackathon Packing List - A Handy Guide
19
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

todoist-scripts

Python
2
star
12

CTF-AI

Java
2
star
13

Motivation.safariextension

New Safari tab page showing your age
JavaScript
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
21

synChroma

๐Ÿ“ฑ๐Ÿ“ฒ TAMUHack Hackathon Project - Transmit data between iPhones using color
Swift
1
star