With the removal of WatchOS3 from being able to directly connect to the Firebase database, I am having issues keeping the watch app up to date with the data if the phone is locked or the app is not active.
I am currently having the watch request updates from the phone in the "awake", which works. However any changes/additions to the data in Firebase does not fire the update on the phone running in the background to notify the watch. If the phone app is open, communication is passed along flawlessly.
I am scoured the Apple docs, but I am not seeing what I am missing to keep the phone / Firebase connection active while in the background.
Has anyone had better luck with this or have a recommendation on a more robust solution?
Current Watch Code/Flow:
func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) {
print("RECEIVED MESSAGE from Phone")
// REMOVED: This is where I parse json return and reloads the view data
replyHandler( [ "Pages" : "Good to Go" ] )
}
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
print ("Watch Activation Complete")
}
override func awake(withContext context: Any?) {
super.awake(withContext: context)
let currentDate = Date()
sendMessageToPhone(command: dataCommands.sendData, value: currentDate.description)
}
func sendMessageToPhone(command: dataCommands, value: String) {
print("SENDING MESSAGE from Watch")
let data = [command.rawValue : value]
session.sendMessage(data, replyHandler: {(data: [String : Any]) -> Void in
print("Phone Got Message")
}, errorHandler: {(error ) -> Void in
print("Phone did not get message.")
self.messageErrorHandler(error: error as NSError)
})
}