0

This IOS app has the watchOS app included, the sending function works an is displayed on the watch, and the Counter counts on the IOS app, now I am wondering if there is an easy way to display the counted numbers on the watch, this is the ContentView Code.

Devices

1

    import SwiftUI

struct ContentView: View {
    var model = ViewModelPhone()
    @State var reachable = "No"
    @State var Message = ""
    @State var GolfCount :Int = 0
    var body: some View {
        VStack{
            Text("Reachable \(reachable)")

            
            Button(action: {
                if self.model.session.isReachable{
                    self.reachable = "Yes"
                }
                else{
                    self.reachable = "No"
                }
            }) {
                Text("Update")
            }
            //mesage input
            TextField("Input your message", text: $Message)
                .padding(100)
            Button(action: {
                //message sending
                self.model.session.sendMessage(["message" : self.Message], replyHandler: nil) { (error) in
                    print(error.localizedDescription)
                }
            }) {
            Text("Send")
            } //golf Counting
            Button(action: {
                
                GolfCount += 1
                })
            {
            Text("Schläge")
            Text(String(GolfCount))
            }}}}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
'''
vimuth
  • 5,064
  • 33
  • 79
  • 116
treenera
  • 19
  • 3
  • Look into AppGroups – lorem ipsum Aug 16 '22 at 18:18
  • You need to use [`WCSession`](https://developer.apple.com/documentation/watchconnectivity/wcsession). AppGroup s haven't been applicable since watchOS2 when the watch code actually ran on the paired phone – Paulw11 Aug 16 '22 at 21:26

0 Answers0