πŸ“±πŸ“² 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 @amzn | formerly @limebike @IBM-Swift
Wilson Ding
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
Apple watch app to interface with Transmission Client

TransmissionWatch Apple watch app to interface with Transmission Client Currrent

Aayush 2 Dec 23, 2021
Shawn Frank 2 Aug 31, 2022
Kiwix for offline access on iOS and macOS

Kiwix for iOS & macOS This is the home for Kiwix apps on iOS and macOS. Mobile app for iPads & iPhones Download the iOS mobile app on iTunes App Store

Kiwix 299 Dec 21, 2022
Bonjour networking for discovery and connection between iOS, macOS and tvOS devices.

Merhaba Bonjour networking for discovery and connection between iOS, macOS and tvOS devices. Features Creating Service Start & Stop Service Stop Brows

Abdullah Selek 67 Dec 5, 2022
A barebones Swift HTTP client with automatic JSON response parsing.

HTTP Client A barebones Swift HTTP client with automatic JSON response parsing. Installation Add HTTP Client as a dependency through Xcode or directly

Joe Masilotti 30 Oct 11, 2022
Fully automatic managed circular image array above UIKit.

Automatic Profile cluster view Fully automatic managed circular image array. Usage From Interface Builder β€’ Drag ProfileClusterView.swift file into yo

Chandan Karmakar 5 Dec 9, 2022
NWReachability - a pure Swift library for monitoring the network connection of iOS devices using Apple's Network framework.

NWReachability is a pure Swift library for monitoring the network connection of iOS devices using Apple's Network framework.

null 4 Dec 2, 2022
A remote for your IR devices for iOS and Mac!

Command your TV, Apple TV or Receiver with your Mac/iOS device through iTach. Screenshots On iOS: On Mac (notification center): How to use Buy a iTach

Michael Villar 19 Nov 4, 2022
Swift Paging is a framework that helps you load and display pages of data from a larger dataset from local storage or over network.

Swift Paging is a framework that helps you load and display pages of data from a larger dataset from local storage or over network. This approach allows your app to use both network bandwidth and system resources more efficiently. It's built on top of Combine, allowing you to harness its full power, handle errors easily, etc.

Gordan GlavaΕ‘ 12 Dec 9, 2022
Open source SDK to quickly integrate subscriptions, stop worring about code maintenance, and getting advanced real-time data. Javascript / iOS glue framework

Open source SDK to quickly integrate subscriptions, stop worring about code maintenance, and getting advanced real-time data. Javascript / iOS glue framework

glassfy 5 Nov 7, 2022
Thin wrapper around NSURLSession in swift. Simplifies HTTP requests.

SwiftHTTP SwiftHTTP is a thin wrapper around NSURLSession in Swift to simplify HTTP requests. Features Convenient Closure APIs Simple Queue Support Pa

Dalton 1.9k Dec 7, 2022
Http Request wrapper written in Swift

Net Net is a HttpRequest wrapper written in Swift Features GET, POST, PUT, DELETE method Powerful request params: nested params, number, string, dic,

Le Van Nghia 304 Jun 29, 2022
Another network wrapper for URLSession. Built to be simple, small and easy to create tests at the network layer of your application.

Another network wrapper for URLSession. Built to be simple, small and easy to create tests at the network layer of your application. Install Carthage

Ronan Rodrigo Nunes 89 Dec 26, 2022
A WIP Swift wrapper for Discord's Bot API.

Quickcord Quickcord is a WIP Swift wrapper for Discord's Bot API. Features (As of right now) Connecting the the gateway and identifying. Literally eve

Ben Sova 4 Aug 7, 2021
Easy to use CFNetwork wrapper for HTTP requests, Objective-C, Mac OS X and iPhone

ASIHTTPRequest is an easy to use wrapper around the CFNetwork API that makes some of the more tedious aspects of communicating with web servers easier

Ben Copsey 5.8k Dec 14, 2022
A custom wrapper over AFNetworking library that we use inside RC extensively

AFNetworkingHelper A very simple wrapper over the most amazing networking library for objective C, AFNetworking. We extensively use it inside RC and i

Betacraft 16 Aug 3, 2021
Easy HTTP Networking in Swift a NSURLSession wrapper with image caching support

Networking was born out of the necessity of having a simple networking library that doesn't have crazy programming abstractions or uses the latest rea

Nes 1.3k Dec 17, 2022
A modern Swift wrapper for Instagram Private API.

Swiftagram is a wrapper for Instagram Private API, written entirely in (modern) Swift. Instagram's official APIs, both the Instagram Basic Display API

Stefano Bertagno 217 Dec 27, 2022