Good morning,
I come to you for a question: When I install my application on my iPhone for the first time, and I install the watch application from the native "Watch" application, the Watch Connectivity function does not work, I have to do the installation from Xcode to the watch for this function to work. Is this normal? if yes, the problem will not arise during a publication? I have the same problem when using watch and iPhone simulators, WatchConnectivity does not work.
I am this error code in Xcode:
-[WCSession handleIncomingUserInfoWithPairingID:]_block_invoke delegate (null) does not implement session:didReceiveUserInfo:, discarding incoming content
Here is the code for the iPhone and the watch:
In my iPhone app:
import WatchConnectivity
let userDefaultsDataVenantWatch = UserDefaults.standard
class PhoneDataModel : NSObject, WCSessionDelegate, ObservableObject {
static let shared = PhoneDataModel()
let session = WCSession.default
@Published var TableauSynchroIphoneVersWatch : [String:String] = ["0":"0"]
@Published var dataWatchVersIphone: [String:String] = ["":""]
override init() {
super.init()
if WCSession.isSupported() {
session.delegate = self
session.activate()
} else {
print("ERROR: Watch session not supported")
}
}
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
if let error = error {
print("session activation failed with error: \(error.localizedDescription)")
return
}
}
func sessionDidBecomeInactive(_ session: WCSession) {
session.activate()
}
func sessionDidDeactivate(_ session: WCSession) {
session.activate()
}
func session(_ session: WCSession, didReceiveUserInfo userInfo: [String : Any]) {
guard let newCount = userInfo["TableauSynchroIphoneWatch"] as? [String:String] else {
print("ERROR: unknown data received from Watch TableauSynchroIphoneWatch")
return
}
DispatchQueue.main.async {
print(newCount)
}
}
}
In my Watch app:
import WatchConnectivity
let userDefaultsDataVenantIphone = UserDefaults.standard
var TableauVenantIphone:[String:String] = ["":""]
class WatchDataModel : NSObject, WCSessionDelegate, ObservableObject {
static let shared = WatchDataModel()
let session = WCSession.default
@Published var TableauSynchroIphoneWatch : [String:String] = ["0":"0"]
override init() {
super.init()
if WCSession.isSupported() {
session.delegate = self
session.activate()
} else {
print("ERROR: Watch session not supported")
}
}
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
if let error = error {
print("session activation failed with error: \(error.localizedDescription)")
return
}
}
func session(_ session: WCSession, didReceiveUserInfo userInfo: [String : Any]) {
guard let newCount = userInfo["TableauSynchroIphoneVersWatch"] as? [String:String] else {
print("ERROR: unknown data received from Watch TableauSynchroIphoneWatch")
return
}
DispatchQueue.main.async {
print(newCount)
}
}
}
Thank for your answers !