dingwilson / multipeer Goto Github PK
View Code? Open in Web Editor NEW📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices
Home Page: http://wilsonding.com/MultiPeer
License: MIT License
📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices
Home Page: http://wilsonding.com/MultiPeer
License: MIT License
weak var delegate: MultiPeerDelegate?
make it public
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.
Hi, Can you add support for tvOS, please?
Author, please, add information to README, see the link below
https://developer.apple.com/forums/thread/659563
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:
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)
Could you please add a browser view controller so that I can create a subview for connection monitoring.
Any solution for this?I tried with the sample project,app still crashed.
It may be worth updating the README.md / Docs explaining you have to enable incoming / outgoing connections in your entitlements.
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
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
it will be work on background after connecting the device ,or notify the nearest device in sleep state.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.