BTW the whole app code is online on GitHub https://github.com/poml88/FLwatch
Sometimes it is good to create such a post just to clear your ming. :-) Then the answer might just occur to you. So five minutes after sending I finally got it.
The problem was simple, I was creating my connectivity manager using @StateObject var watchConnector = WatchConnectivityManager()
in ContentView.swift, but then recreating it in two other places in the phone app, however only on ONE other place in the watch app, so that is why it worked on the watch, but not on the phone, because on the watch the class I did not (wrongly) create another instance.
So, I changed all the occurrences of @StateObject var watchConnector = WatchConnectivityManager()
to
@StateObject var watchConnector = WatchConnectivityManager.shared
and voila now it works fine. I also should have been suspicious, because in the logs I got already in progress or activated
but I did not really know how to interpret this.
Still I got the impression it is not perfect like this. Maybe it could be improved?
On the phone app I have this in ContentView.swift
import SwiftUI
import OSLog
struct ContentView: View {
@StateObject var watchConnector = WatchConnectivityManager.shared
@State var selectedTab = "Home"
var body: some View {
That should be the first time the connectivity manager is created.
Then I access the watch connector in two other files in the same way.
import SwiftUI
import OSLog
import SecureDefaults
struct PhoneAppConnectView: View {
@StateObject var watchConnector = WatchConnectivityManager.shared
and
import SwiftUI
struct PhoneAppInsulinDeliveryView: View {
@AppStorage(SharedData.Keys.insulinSelected.key, store: SharedData.defaultsGroup) private var insulinSelected: Double = 0.5
@Environment(\.dismiss) var dismiss
@StateObject var watchConnector = WatchConnectivityManager.shared
Is this the proper way of managing this watch connector?