Watch OS3 cannot get Accelerometer data when screen is off - ios

It's seems no way to get realtime Accelerometer data on WatchOS after wrist down ,screen is off. get data from CMMotionManager will stop after seconds for Apple's battery care.
You can query data from HKWorkoutSession in background ,for example: step count、calories、heart beats rate ,but it cannot query Accelerometer data or CMDeviceMotion data.
I google it a lot and I test with this code.
https://developer.apple.com/videos/play/wwdc2016/713/
WWDC sample code download
It's not accurate because of screen off problem. It will not print CMDeviceMotion data in XCode when your screen off .
Someone says MSensorRecorder maybe work, but it has 3 sec delay.
Is there a way to get this?

When screen is off, your app is being suspended. So, your the problem is not "CMMotionManager does not give data when screen is off", but "my app is not running when screen is off".
As a workaround, you can start workout: while workout is active, your app will be running in background and you can continue requesting data from CMMotionManager same way as you are doing it now. But be careful: app can not use more than 15% of CPU while running in background workout, else it will be killed by watchdog.
Watch this WWDC videos for more details on workout and background modes: Building Great Workout Apps, Keeping Your Watch App Up to Date,
Architecting for Performance on watchOS 3

Related

Apps battery usage is high although no code is being execuded IOS Swift

I have an IOS Chat Application that lets users chat with each other and lets users join a video call. Therefore the app has a lot of pods installed. My problem now is that whenever I launch the app the battery usage is immediately at the border of "high battery state" and "very high battery state" in the Xcode debugger. I also tried to just launch the app with nearly no code being execuded at all (just Firebase User LogIn), but the battery usage is still the same. Is there any solution to this?
A possible reason for this extreme high battery usage could be that because the app uses background modes to stay active in background when in a video call it also stays active in background when the user isn´t in a video call. Is it possible to define when the app should stay fully active in background and when it shouldn´t? And does the staying active in background actually influences the battery usage?

invoke a alarm sound when ios app is in background and someone pick it, using core motion

invoke a alarm when someone touched the iPhone or iPad and a app is running in background.
this is happening into a ios app i.e. iAntiTheft
iAntiTheft is not using the location i checked the permission of the app, in a scenario i put the app in background activating motion alert and device get's locked after some time, now i pick the device, it immediately show a Notification and start alarm on high volume.
one More thing here to notice it always playing a low volume beep beep after enabling the motion sensor alert. any help appreciated.
how can i achieve this.
The answer to get Core Motion Update when the app is in background and the device locked. in both case just put an audio with background mode playing after the core motion updates function, now the device will go to background or get locked you always getting the core motion coordinates updates
Repo Link Providing soon

How to continue collect motion sensor data on apple watch?

I'm developing an app on apple watch which needs continuous access to gyroscope and accelerometer data. But once the watch rotates, the screen turns off and apparently it stops accessing motion data while the screen is off. I tried to keep the screen on but apple watch doesn't have that feature, any thoughts around this?
Thanks
You'll need to start an HKWorkoutSession.
The app can continue to access data from Apple Watch’s sensors in the background, letting you keep the app up to date at all times. For example, a running app can continue to track the user’s heart rate, ensuring that the most recent heart rate data is displayed whenever the user raises their wrist.

ios app, running accelerometer while the app is in the background

I have an app using accelerometer. When a certain motion is detected, i am trying to make my iphone vibrate. While the app is in the foreground, and I conduct a certain motion, it vibrates. But it does not when the app is in the background.
I have a counter that detects this motion. When I execute this motion while in the background for three times, although it does not emit any vibration, after I transition back to foreground, the counter is increased by three. So I know the accelerometer is working. Or is putting the motions in a queue and executing it when the app comes back to foreground.
And I'm not making a rookie mistake by touching the phone's vibrate to off.
I'm quite not sure where to go from here. Is iphone inherently not capable of capturing and processing accelerometer data while in the background? Or is there something I'm not doing correctly?
In iOS there are only a certain type of activities allowed in background. Here you can check them: Background Modes.
I'm currently working in an app that uses sensors like the accelerometer and I get updates from it using the CoreLocation delegate method didUpdateLocation, since using the GPS to locate the device is one of the Apple allowed background modes. I hope this helps you!

Shake functionality in a music application

I have developed a small music app by using AVPlayer and MPMediaPickerControlLibrary with all the normal required functionalities for a music app. The app is also capable of running in the background when the screen is locked.
Now, what I want is to start the app when the screen is locked through a shake and soon as the app starts the current song should start playing.
I am not able to achieve this from a long time
Any suggestions on this will be highly appreciated or any other workaround apart from shake to turn on the music in the app when the screen is locked in iPhone.
Thanks in advance.
You need to implement the a CMMotionManager object, but keeping it running all the time in background will be a major power consumption issue.
Modifying the updateInterval property to reduce the number of updates will defeat the purpose, given that you may miss a shake in background.
Now, if the app was terminated by the user, then no motionManager object will be available until the user launches the app again.

Resources