📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices

Overview

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.

Comments
  • Issues with sending images

    Issues with sending images

    Hi,

    Not sure if this is an issue or just a problem with my syntax, but when sending images, nothing is received. I can send strings no problem.

    Starting connection:

    MultiPeer.instance.delegate = self
            
            MultiPeer.instance.initialize(serviceType: "livestream")
            MultiPeer.instance.autoConnect()
    

    Sending:

    MultiPeer.instance.send(object: imageView, type: DataType.image.rawValue)

    Receiving:

    extension loadViewController: MultiPeerDelegate {
    
        func multiPeer(didReceiveData data: Data, ofType type: UInt32) {
            switch type {
            case DataType.image.rawValue:
                guard let image = data.convert() as? UIImage else { return }
                print("___________________________image recieved!___________________________")
                break;
                
            default:
                break;
            }
        }
        func multiPeer(connectedDevicesChanged devices: [String]) {
        }
    }
    

    Any help would be appreciated!

    Many Thanks, Ben

    bug 
    opened by benmckillop 23
  • Added source peer on MultipeerDelegate didReceveData method

    Added source peer on MultipeerDelegate didReceveData method

    This PR exposes source peer when data is received. It's useful when you want to forward a message to other peers, excluding source peer to avoid loops/duplication

    opened by thibauddavid 3
  • Added danger support

    Added danger support

    Features:

    • Notifies user if xcodebuild contains warnings/errors
    • Notifies user if PR contains commit with merge message (asks them to rebase)
    • Notifies user if [WIP] found in PR head
    • Notifies user for SwiftLint issues
    • [More to Come]
    opened by dingwilson 0
  • Warnings of depreciated methods in MultiPeer.swift file

    Warnings of depreciated methods in MultiPeer.swift file

    Getting these alert warnings when I compile, thought they might want to be addressed/updated:

    Line 159: 'archivedData(withRootObject:)' was deprecated in iOS 12.0: Use +archivedDataWithRootObject:requiringSecureCoding:error: instead

    line 174: 'archivedData(withRootObject:)' was deprecated in iOS 12.0: Use +archivedDataWithRootObject:requiringSecureCoding:error: instead

    line 297: 'unarchiveObject(with:)' was deprecated in iOS 12.0: Use +unarchivedObjectOfClass:fromData:error: instead

    line 302: 'archivedData(withRootObject:)' was deprecated in iOS 12.0: Use +archivedDataWithRootObject:requiringSecureCoding:error: instead

    opened by thoughtcastapp 1
  • Sending data to a peer that is not nearby

    Sending data to a peer that is not nearby

    Hi @dingwilson,

    I like your wrapper for MultiPeer and I was thinking what if we store a particular peerID when it is nearby (for instance in userDefaults) and when they are not nearby, try sending a message to that peerID.

    For example peer A wants to send a msg to Peer C but they are not nearby but B is nearby to A and also nearby to C.

    A-----B-------C

    opened by iHamzaaK 3
  • Invite peer manually

    Invite peer manually

    Add shouldInvitePeerDidFound delegate and expose invite peer method to make developer invite peer manually. If there is no delegate, then auto invite peer and reconnect issue is possible to be raised.

    opened by kf99916 1
Owner
Wilson Ding
I build cool stuff people use @limebike | formerly @amzn @IBM-Swift
Wilson Ding
BluetoothKit Easily communicate between iOS devices using BLE.

BluetoothKit Easily communicate between iOS devices using BLE. Background Apple mostly did a great job with the CoreBluetooth API, but because it enca

Rasmus Høhndorf Hummelmose 2.1k Jan 8, 2023
A very simple library to discover and retrieve data from nearby devices (even if the peer app works at background).

Discovery: A simple library to discover and retrieve data from nearby devices. Discovery is a very simple but useful library for discovering nearby de

Ömer Faruk Gül 412 Dec 19, 2022
Build your own 'AirTags' 🏷 today! Framework for tracking personal Bluetooth devices via Apple's massive Find My network.

OpenHaystack is a framework for tracking personal Bluetooth devices via Apple's massive Find My network.

Secure Mobile Networking Lab 5.8k Jan 9, 2023
A simple framework that brings Apple devices together - like a family

Apple Family A simple framework that brings Apple devices together - like a family. It will automatically use bluetooth, wifi, or USB to connect and c

Kiran 62 Aug 21, 2022
AZPeerToPeerConnectivity is a wrapper on top of Apple iOS Multipeer Connectivity framework. It provides an easier way to create and manage sessions. Easy to integrate

AZPeerToPeerConnection Controller Features Multipeer Connectivity Connection via Bluetooth or Wifi No need write all session, browser, services delega

Afroz Zaheer 66 Dec 19, 2022
RxBluetoothKit is a Bluetooth library that makes interaction with BLE devices much more pleasant.

RxBluetoothKit is a Bluetooth library that makes interaction with BLE devices much more pleasant. It's backed by RxSwift and CoreBluetooth and it prov

Polidea 1.3k Jan 6, 2023
Fluetooth - Flutter library for sending bytes to Bluetooth devices on Android/iOS

A Flutter library for sending bytes to Bluetooth devices. Available on Android a

Iandi Santulus 1 Jan 2, 2022
The official Swift Library for Vital API, HealthKit and Devices

vital-ios The official Swift Library for Vital API, HealthKit and Devices Install We currently support SPM. Documentation Please refer to the official

Vital 17 Dec 22, 2022
CombineCoreBluetooth is a library that bridges Apple's CoreBluetooth framework and Apple's Combine framework

CombineCoreBluetooth is a library that bridges Apple's CoreBluetooth framework and Apple's Combine framework, making it possible to subscribe to perform bluetooth operations while subscribing to a publisher of the results of those operations, instead of relying on implementing delegates and manually filtering for the results you need.

Starry 74 Dec 29, 2022
iOS Bluetooth LE framework

Features A futures interface replacing protocol implementations. Timeout for Peripheral connection, Service scan, Service + Characteristic discovery a

Troy Stribling 696 Dec 25, 2022
Bluejay is a simple Swift framework for building reliable Bluetooth LE apps.

Bluejay is a simple Swift framework for building reliable Bluetooth LE apps. Bluejay's primary goals are: Simplify talking to a single Bluetooth LE pe

Steamclock Software 1k Dec 13, 2022
An open-source Swift framework for building event-driven, zero-config Multipeer Connectivity apps

PeerKit An open-source Swift framework for building event-driven, zero-config Multipeer Connectivity apps Usage // Automatically detect and attach to

JP Simard 861 Dec 23, 2022
Blocks Based Bluetooth LE Connectivity framework for iOS/watchOS/tvOS/OSX. Quickly configure centrals & peripherals, perform read/write operations, and respond characteristic updates.

ExtendaBLE Introduction ExtendaBLE provides a very flexible syntax for defining centrals and peripherals with ease. Following a blocks based builder a

Anton 94 Nov 29, 2022
📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices

A wrapper for Apple's MultipeerConnectivity framework for offline data transmission between Apple devices. This framework makes it easy to automatical

Wilson Ding 197 Nov 2, 2022
a playground app using `MultipeerConnectivity` to transfor data wirelessly between iOS / iPadOS

README An example app using MultipeerConnectivity to transfor data wirelessly between iOS / iPadOS. Both using Data and Stream to transfer data are su

null 3 Aug 6, 2022
Functional wrapper for Apple's MultipeerConnectivity framework.

A functional wrapper for the MultipeerConnectivity framework. PeerConnectivity is meant to have a lightweight easy to use syntax, be extensible and fl

Reid Chatham 48 Jun 28, 2021
A testable RxSwift wrapper around MultipeerConnectivity

A testable RxSwift wrapper around MultipeerConnectivity

RxSwift Community 69 Jul 5, 2022
A testable RxSwift wrapper around MultipeerConnectivity

A testable RxSwift wrapper around MultipeerConnectivity RxMultipeer is a RxSwift wrapper for MultipeerConnectivity. Using the adapter pattern, we can

RxSwift Community 69 Jul 5, 2022
A peer to peer framework for OS X, iOS and watchOS 2 that presents a similar interface to the MultipeerConnectivity framework

This repository is a peer to peer framework for OS X, iOS and watchOS 2 that presents a similar interface to the MultipeerConnectivity framework (which is iOS only) that lets you connect any 2 devices from any platform. This framework works with peer to peer networks like bluetooth and ad hoc wifi networks when available it also falls back onto using a wifi router when necessary. It is built on top of CFNetwork and NSNetService. It uses the newest Swift 2's features like error handling and protocol extensions.

Manav Gabhawala 93 Aug 2, 2022
LaiFeng IOS Live Kit,H264 and AAC Hard coding,support GPUImage Beauty, rtmp transmission,weak network lost frame,Dynamic switching rate

LFLiveKit LFLiveKit is a opensource RTMP streaming SDK for iOS. Features Background recording Support horizontal vertical recording Support Beauty Fac

null 4.3k Jan 6, 2023