Latest 1.1
Homepage https://github.com/ajsagar92/SmartMultipeer
License Copyright
Platforms ios 11.0
Dependencies RealmSwift
Authors

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run from the Example directory first.

Requirements

iOS Version required is 11.0

Installation

SmartMultipeer is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'SmartMultipeer'

Usage

  1. Import the module
    import SmartMultipeer

Classes & Protocol

You need to use PeerConnectivity.swift file that manages everything and contains all required methods. DataSync.swfit protocol contains DataSyncDelegate that needs to be implemented in class to receive data. It contains 4 methods that are:

    func sync(dataDidReceive: Any, ofType: Type, at: Date)

Method is called when data is received on other device

    func update(devices: [PeerDevice], at: Date)

Method is called when any device is added / lost

    func lost(device: PeerDevice, at: Date)

Method is called when any device is lost. This method is optional

    func acknowledge(from: PeerDevice, at: Date, forDataID: Any)

Method is called when data is received and sender will be acknowledged. This method is optional

How to start

  1. Initialize service type by using:

    PeerConnectivity.instance.service = "sample-service"
  2. Setup Multipeer Connectivity

    PeerConnectivity.instance.setup(fromViewController: self, withDelegate: self)
  3. Connect Users

    a. Individually

    PeerConnectivity.instance.connect(forUser: .Peer)
    PeerConnectivity.instance.connect(forUser: .Host)

    b. Simultaneously

    PeerConnectivity.instance.autoConnect()
  4. To send data to connected peers
    func send(data: Any, ofType: Type, withID: Any)

    You can send data of any type whether its primitive or custom model that is designed or encapsulated in class and ‘ofType’ that can contain values defined in Type.swift enum. ‘withID’ can be used to validated at the time of acknowledgement.

Other helper methods & properties

PeerConnectivity.instance.disconnect()

Disconnect all peers and will stop advertising and browsing

PeerConnectivity.instance.getAllRegisteredDevices()

Returns the history of devices connected up till now

PeerConnectivity.instance.peer

Returns the information of current device

PeerConnectivity.instance.getAvailablePeers()

Return all available peers ready to get connected

PeerConnectivity.instance.getConnectedPeers()

Returns all connected peers

Author

AJ Sagar Parwani
Email: [email protected]

License

SmartMultipeer is available under the Author’s license. See the LICENSE file for more info.

Latest podspec

{
    "name": "SmartMultipeer",
    "version": "1.1",
    "summary": "Multipeer Connectivity for iOS Devices with Acknowlegement",
    "platforms": {
        "ios": "11.0"
    },
    "swift_version": "4.2",
    "description": "Smart Multipeer Connectivity designed with acknowledgment facility that includes the time of delivery with the id of data sent. You can set primary id of your model which you want to sync",
    "homepage": "https://github.com/ajsagar92/SmartMultipeer",
    "license": {
        "type": "Copyright",
        "file": "LICENSE"
    },
    "authors": {
        "Ajay Sagar Parwani": "[email protected]"
    },
    "source": {
        "git": "https://github.com/ajsagar92/SmartMultipeer.git",
        "tag": "1.1"
    },
    "source_files": "SmartMultipeer/**/*.{swift}",
    "dependencies": {
        "RealmSwift": []
    }
}

Pin It on Pinterest

Share This