I have an app opened on my iPhone, I would like to know if there is a way to call remotely a function of this app from my apple-watch (watchOS 3) by simply tapping a button?
The function concerned stores data from the accelerometer. I searched on the Internet. I found a beginning of solution on Stackoverflow but it still remains a bit mysterious for me.
You can transmit information from the watch app to the iOS app using the WCSession APIs. Assuming you have a paired and activated WCSession, from your watch app you can call WCSession.sendMessage:replyHandler:errorHandler and the message will be transmitted straight away to the iOS device. Your foreground iOS app will need to be listening for a message using WCSessionDelegate.session:didReceiveMessage:replyHandler. From there based upon the message received you can invoke your function.