feat: Simple bluetooth status indication
This commit is contained in:
12
.gitignore
vendored
Normal file
12
.gitignore
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
.DS_Store
|
||||
/.build
|
||||
/Packages
|
||||
xcuserdata/
|
||||
DerivedData/
|
||||
.swiftpm/configuration/registries.json
|
||||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||
.netrc
|
||||
|
||||
/xtool
|
||||
|
||||
*.log
|
||||
5
.sourcekit-lsp/config.json
Normal file
5
.sourcekit-lsp/config.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"swiftPM": {
|
||||
"swiftSDK": "arm64-apple-ios"
|
||||
}
|
||||
}
|
||||
10
Info_extra_tags.plist
Normal file
10
Info_extra_tags.plist
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSBluetoothAlwaysUsageDescription</key>
|
||||
<string>This app uses Bluetooth to connect to devices.</string>
|
||||
<key>NSBluetoothPeripheralUsageDescription</key>
|
||||
<string>This app uses Bluetooth.</string>
|
||||
</dict>
|
||||
</plist>
|
||||
24
Package.swift
Normal file
24
Package.swift
Normal file
@@ -0,0 +1,24 @@
|
||||
// swift-tools-version: 6.0
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "ScoobyTag",
|
||||
platforms: [
|
||||
.iOS(.v15),
|
||||
.macOS(.v14),
|
||||
],
|
||||
products: [
|
||||
// An xtool project should contain exactly one library product,
|
||||
// representing the main app.
|
||||
.library(
|
||||
name: "ScoobyTag",
|
||||
targets: ["ScoobyTag"]
|
||||
),
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "ScoobyTag"
|
||||
),
|
||||
]
|
||||
)
|
||||
23
Sources/scoobytag/BluetoothManager.swift
Normal file
23
Sources/scoobytag/BluetoothManager.swift
Normal file
@@ -0,0 +1,23 @@
|
||||
import SwiftUI
|
||||
import CoreBluetooth
|
||||
|
||||
final class BluetoothManager: NSObject, ObservableObject {
|
||||
private var centralManager: CBCentralManager!
|
||||
@Published var status = "Starting..."
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
centralManager = CBCentralManager(delegate: self, queue: nil)
|
||||
}
|
||||
}
|
||||
|
||||
extension BluetoothManager: CBCentralManagerDelegate {
|
||||
func centralManagerDidUpdateState(_ central: CBCentralManager) {
|
||||
switch central.state {
|
||||
case .poweredOn:
|
||||
status = "Bluetooth is on"
|
||||
default:
|
||||
status = "Bluetooth unavailable"
|
||||
}
|
||||
}
|
||||
}
|
||||
16
Sources/scoobytag/ContentView.swift
Normal file
16
Sources/scoobytag/ContentView.swift
Normal file
@@ -0,0 +1,16 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ContentView: View {
|
||||
@EnvironmentObject var bluetoothManager: BluetoothManager
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Image(systemName: "globe")
|
||||
.imageScale(.large)
|
||||
.foregroundStyle(.tint)
|
||||
Text("Hello, world!")
|
||||
Text(bluetoothManager.status)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
13
Sources/scoobytag/ScoobyTagApp.swift
Normal file
13
Sources/scoobytag/ScoobyTagApp.swift
Normal file
@@ -0,0 +1,13 @@
|
||||
import SwiftUI
|
||||
import CoreBluetooth
|
||||
|
||||
@main
|
||||
struct ScoobyTagApp: App {
|
||||
@StateObject private var bluetoothManager = BluetoothManager()
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
ContentView()
|
||||
.environmentObject(bluetoothManager)
|
||||
}
|
||||
}
|
||||
}
|
||||
19
makefile
Normal file
19
makefile
Normal file
@@ -0,0 +1,19 @@
|
||||
.PHONY: all deploy log log_err clean
|
||||
|
||||
all: build
|
||||
|
||||
build:
|
||||
xtool dev build
|
||||
|
||||
deploy:
|
||||
xtool dev
|
||||
|
||||
log:
|
||||
idevicesyslog | grep cooby > out.log
|
||||
|
||||
log_err:
|
||||
cat out.log | grep rror
|
||||
|
||||
clean:
|
||||
-rm -rf .build
|
||||
-rm -rf xtool
|
||||
Reference in New Issue
Block a user