Giter Site home page Giter Site logo

dingwilson / multipeer Goto Github PK

View Code? Open in Web Editor NEW
223.0 9.0 31.0 3.18 MB

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

Home Page: http://wilsonding.com/MultiPeer

License: MIT License

Ruby 8.93% Swift 85.48% Objective-C 5.59%
ios swift multipeerconnectivity connection mesh-networks cocoapods multipeer carthage multipeerconnectivity-framework swift-package-manager

multipeer's People

Contributors

dingwilson avatar ioviov avatar kierancrown avatar thibauddavid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

multipeer's Issues

Fails to connect on iOS 17

I have a very janky implementation of MultiPeer myself and this works fine on iOS17, but I wanted to use a more tidy solution and came across your library.
Sadly, it doesnt seem to work on iOS 17 currently. You sample app and a custom implementation of you library both failed to connect 2 physical devices. It didn't even ask me for local network access permission.

Connection between iOS 17 and macOS 14

My test code is:

import SwiftUI
import MultiPeer

struct ContentView: View {
    @ObservedObject var model = ViewModel()
    
    var body: some View {
        VStack {
            Text("Connected devices: ") + Text(model.connectedDevices.count == 0 ? "NONE" : model.connectedDevices)
            
            Text("Connected peers: ") + Text("\(model.instance.connectedPeers.description )")
            
            Text("Is connected: " + "\(model.instance.isConnected )")
            
            Button("refresh") {
                model.objectWillChange.send()
            }
            
            Button("send") {
                model.send()
            }
        }
        .padding()
    }
}

class ViewModel: ObservableObject {
    @Published var connectedDevices: String = ""
    var instance: MultiPeer { MultiPeer.instance }
    
    init() {
        instance.initialize(serviceType: "LFT-app")
        instance.delegate = self
        instance.autoConnect()
    }
    
    func send() {
        instance.send(object: "Hello World!", type: DataType.string.rawValue)
    }
}

extension ViewModel: MultiPeerDelegate {
    func multiPeer(didReceiveData data: Data, ofType type: UInt32, from peerID: MCPeerID) {
        switch type {
        case DataType.string.rawValue:
            let string = data.convert() as! String
            
            print("string recieved: \(string)")
            // do something with the received string
            break
            
        case DataType.image.rawValue:
//            let image = NSImage(data: data)
            print("image recieved")
            // do something with the received UIImage
            break
            
        default:
            print("video recieved")
            break
        }
    }
    
    func multiPeer(connectedDevicesChanged devices: [String]) {
        connectedDevices = devices.joined(separator: ", ")
    }
}

enum DataType: UInt32 {
    case string = 1
    case image = 2
    case video = 3
}

my project config:

enter image description here

enter image description here

enter image description here

In the same time I have connection in case of 2 apps run on macOS.

Environment with issue:
macOS: 14.3 (23D56)
iOS: 17.3.1 (21D61)

Update Documentation

It may be worth updating the README.md / Docs explaining you have to enable incoming / outgoing connections in your entitlements.

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

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

background process

it will be work on background after connecting the device ,or notify the nearest device in sleep state.

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.