We want to use apple watch as a device and simulate its motion on the iPhone based on accelerometer values,
Project Flow :
- We have created a single view Application iPhone app
- Added Apple Watch target
- Got values of the accelerometer(x, y, and z) in Apple Watch app using CoreMotion framework
- We store those value in Dictionary
- We send Dictionary using WatchConnectivity
- Received accelerometer(x, y, and z) values in the iPhone App
Detail Development :
We are getting accelerometer values using the following method,
open func startAccelerometerUpdates(to queue: OperationQueue, withHandler handler: @escaping CMAccelerometerHandler)
After getting these accelerometer(x , y and z) values we are sending it iPhone app using
func updateApplicationContext(_ applicationContext: [String: Any]) throws
Problem Faced:
We are getting accelerometer sensor values only when the Apple Watch app is in the foreground state, once Apple Watch App goes in background state no data received.