Apple Watch stop fetching device motion data when user moves wrist

I have created a watch os app. The app has two buttons(blue and red). When you press the blue button the app fetches device motion data and sends it to a firebase database and prints it to the Xcode console. When you press the stop button, the app stops fetching data.

The problem I am encountering is that when the user moves his wrist, the app stops fetching device motion data(no button has been pressed yet).

I have tried creating a session and keeping the app as the frontmost app. But it still gives me the same error. Please help me what should I do?

video link: https://1drv.ms/v/s!AhWiDPLRyXmM9XNYO7AkRPPSBzSG

You need to create a HKworkoutSession and collect the motion data when the session is active. The session allows you to collect motion data even in the background i.e., when the screen is turned off. Use the below given link to know more about creating a workout session (https://developer.apple.com/documentation/healthkit/workouts_and_activity_rings/build_a_workout_app_for_apple_watch).

Apple Watch stop fetching device motion data when user moves wrist
 
 
Q