I'm using the following code to get CMMotionActivity updates on iPhone and apple watch, RESPECTIVELY. It works great on iPhone, i.e. motionActivityString keeps getting updated immediately and infinitely. However, when running the same code on apple watch, the string is only updated once rather than continuously.
So my question is how to get continuous update on apple watch, just like the iphone does? Thanks!
class MyMotionManager {
@Published var motionActivityString: String = ""
private let activityManager = CMMotionActivityManager()
func checkMotionActivityInForeground() {
if CMMotionActivityManager.isActivityAvailable() {
activityManager.startActivityUpdates(to: OperationQueue.main) { (motionActivity) in
guard let activity = motionActivity else {return}
print(activity)
// The string is updated (almost) immediately and continuously when running on iPhone.
// However, it's only updated once when running on watch.
if activity.stationary {
self.motionActivityString = "Stationary"
} else {
self.motionActivityString = "Moving"
}
}
}
}