Created
January 15, 2023 19:41
-
-
Save wizard1066/73b9cd9b42593d437735af8c992ad2de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import MultipeerConnectivity | |
import Combine | |
let feedback = PassthroughSubject<CGPoint,Never>() | |
let screenSize: CGRect = UIScreen.main.bounds | |
let screenWidth: CGFloat = UIScreen.main.bounds.width | |
let screenHeight: CGFloat = UIScreen.main.bounds.height | |
struct Fonts { | |
static func avenirNextCondensedBold (size: CGFloat) -> Font { | |
return Font.custom("AvenirNextCondensed-Bold", size: size) | |
} | |
static func neutonRegular (size: CGFloat) -> Font { | |
return Font.custom("Neuton-Regular", size: size) | |
} | |
} | |
struct ContentView: View { | |
@StateObject var connectSession = MultipeerSession.shared | |
var body: some View { | |
VStack { | |
Circle() | |
.fill(Color.red) | |
.frame(width: 128, height: 128) | |
.onTapGesture { | |
let info = "stop".data(using: .utf8) | |
do { | |
let foo = connectSession.session.connectedPeers | |
try connectSession.session.send(info!, toPeers: foo, with: MCSessionSendDataMode.reliable) | |
} catch { | |
print("failed") | |
} | |
}.overlay(Text("STOP").font(Fonts.avenirNextCondensedBold(size: 48)) | |
.foregroundColor(Color.white)) | |
.padding() | |
Circle() | |
.fill(Color.green) | |
.frame(width: 128, height: 128) | |
.onTapGesture { | |
let info = "free".data(using: .utf8) | |
do { | |
let foo = connectSession.session.connectedPeers | |
try connectSession.session.send(info!, toPeers: foo, with: MCSessionSendDataMode.reliable) | |
} catch { | |
print("failed") | |
} | |
}.overlay(Text("GO").font(Fonts.avenirNextCondensedBold(size: 48)) | |
.foregroundColor(Color.white)) | |
.padding() | |
} | |
.padding() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment