WatchShareKit
WatchShareKit is a sender and receiver library used to send secrets from iOS apps to watchOS apps.
Usage
Add https://github.com/Aayush9029/WatchShareKit/
project dependency on Xcode
? Sender
import SwiftUI
import WatchConnectivity
import WatchShareKit
struct ContentView: View {
@StateObject var phoneSender: PhoneSender = .init()
@State private var message: [String: Any] = ["your-key": "value"]
var body: some View {
VStack {
if phoneSender.isPaired() {
Button("Share Password") {
phoneSender.shareSheet.toggle()
}
.sheet(isPresented: $phoneSender.shareSheet) {
ShareKeys(message: message)
.environmentObject(phoneSender)
}
} else { Text("Apple Watch Not Paired") }
}
.onChange(of: phoneSender.shareState) { newState in
if newState == .shared { phoneSender.shareSheet.toggle() }
}
}
}
You can also use .onAppear
and toggle sheet accordingly for seamingless experience.
⌚ Receiver
import SwiftUI
import WatchConnectivity
import WatchShareKit
struct ContentView: View {
@StateObject var watchReceiver: WatchReceiver = .init()
var body: some View {
VStack {
if let message = watchReceiver.gotMessage {
Text(message["your-key"].value)
}
}
}
}
You can also use .onChange
to manipulate the data accordingly.
TODO:
- Create remote package.
- Support shared decodable structs for keys.