Core Motion

RSS for tag

Process accelerometer, gyroscope, pedometer, and environment-related events using Core Motion.

Core Motion Documentation

Posts under Core Motion tag

36 Posts
Sort by:
Post not yet marked as solved
0 Replies
319 Views
Hello, When sometimes have bad values when reading the AbsoluteAltitude of the Watch. I'm running WatchOS 10.2 and it seems to be a new issue/bug. When I print out the debugDescription of the received data, I got a statusInfo field at 0 when it works, and at 2 when not. But I didn't find any explanation of the value nor how to access it. // OK: 0 Optional(AbsoluteAltitude: 223.266052, Accuracy: 6.944067, Precision 0.500000, statusInfo: 0, timestamp :726142069.230969) // NOT OK: 2 Optional(AbsoluteAltitude: 121.610824, Accuracy: 3.156758, Precision 5.000000, statusInfo: 2, timestamp :726152607.239057) Have someone experienced similar issues or now what this field is for? Thx and greetings!
Posted
by
Post not yet marked as solved
0 Replies
299 Views
Starting at point zero. I want to calculate the position of the iphone. I've read and many people say this is not possible but this was in 2012 ish. I'm sure the sensors have imporved and this is possible now
Posted
by
Post not yet marked as solved
0 Replies
321 Views
I'm building a physical therapy app and as part of it, I want the app to oversee and measure certain exercises that the user will do. I'm not sure if I should use Core Motion, location services, or something else. These are the specific things we want to measure: The user walks for 6 minutes. At the end of it, we tell them how far they walked. The user runs for 30 seconds. We tell them their average speed and peak speed. The user does a broad jump: basically just jumping forward as far as they can. We want to measure the distance jumped. I'm thinking location services might work for #1 but I doubt it will be accurate enough for #2. For #3 I thought I could do this with the accelerometer if I took readings at short intervals and combined them with something like the trapezoidal rule, but I can't get this to produce a reliable result. Let me know what you think, thanks.
Posted
by
Post not yet marked as solved
1 Replies
323 Views
I am currently developing app that counts the Steps, and for that I am using the pedometer. I am not sure of how frequent pedometer provides updates, in my case it provides update around 3 second. There is nothing mentioned about frequency of Data in Official documentation of Apple or Any ways to set the Frequency. Application is in Both iOS and WatchOS plateform To achieve data i have tried following things: With startUpdates(from: Date) pedometer.startUpdates(from: Date()) { [weak self] pedometerData, error in guard let data = pedometerData, error == nil else { return } DispatchQueue.main.async { self?.stepCount = data.numberOfSteps.intValue } } With queryPedometerData() timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] _ in self?.fetchPedometerData() } private func fetchPedometerData() { pedometer.queryPedometerData(from: Date().addingTimeInterval(-1), to: Date()) { [weak self] pedometerData, error in guard let data = pedometerData, error == nil else { return } DispatchQueue.main.async { self?.stepCount = data.numberOfSteps.intValue } } } I have done this both implementation but Not getting desired results. I want data every second, Could it be possible ? Any help or leads would really helpful Thank You :)
Posted
by
Post not yet marked as solved
1 Replies
411 Views
Hey, everyone! I've been testing my .swiftpm app on an iPhone. If you're wondering about how I made the connections, I used a cable plugged into my Mac so that Xcode could communicate with the phone. Do you think that evaluators of the app will be alright with this method of testing it out as well? I'm particularly leaning towards the iPhone platform because my app requires a pedometer. Thanks! Ethan
Posted
by
Post not yet marked as solved
1 Replies
348 Views
Hello All, I am building an application that involves the usage of accelerometer data. How I handle the data will change based on the accelerometer specifications. I have been looking all over for the accelerometer specifications for the iPhone13 (the iPhone that I am testing my application on), but I cannot find it anywhere. Is it public knowledge?
Posted
by
Post not yet marked as solved
0 Replies
322 Views
Hi all, I am trying to build an app which, on support Apple Watch's (currently just the Ultra's), will detect when the watch has been submerged and will start to report temperature from the sensor. I have followed the developer articles I could find around CMWaterSubmersionManager and have set up a simple class to interact with it. It is now that I want to run my app and test if it is working as I expect it to etc. However I noticed that the waterSubmersionAvailable is only set to true on physical Apple Watch Ultra and Ultra 2. This is rather inconvenient as it means that for the next week or so while developing this feature I will have to stick my arm wearing the watch into a container of water to test the feature. Just wondering if there is any easier way to debug this stuff that anyone has figured out? It would be ideal if this could just be done in the simulator similar to how other device conditions can be induced. I did notice the "Enable Easy Submersion" option in the Debug menu, however I could not figure out a difference between having this on or off, and could not find any explanation of what it actually does on the docs. Does anyone have any experience with this either? Any advice would be appreciated, and to any Apple engineers who may see this, please please please add an option to be able to debug this stuff in the Simulator
Posted
by
Post not yet marked as solved
0 Replies
229 Views
I'm trying to create a productivity app that utilizes gyroscope data to detect when the phone is picked up. However, in my code, it seems that after I detect the phone flipping over, gyro updates become unavailable and I start receiving the sentinel value instead, which causes the code to not work properly. What happens is that I will receive gyro updates until faceUp changes value, at which point gyroData becomes unavailable. let dTheta = Double(self.manager.gyroData?.rotationRate.y ?? 0) if dTheta > 0.1 || dTheta < -0.1 { totalRotation = totalRotation + dTheta } tO = Date.now if(totalRotation >= 0.9 || totalRotation <= -0.9) { //Block that detects a phone flip if faceUp == true { faceUp = false } else if faceUp == false { faceUp = true stopText = "Timer paused at \(currentTimeRemaining)" } totalRotation = 0 } guard shouldProceed() else { return } currentTimeRemaining = dispTime(mustRedo: mustRedo) keepScreenOn() let hours = job.hours let mins = job.mins let secs = job.seconds if mins == 0 && hours == 0 { minsDone = true } if secs == 0 && mins == 0 { secsDone = true } if mins == 0 && minsDone == false { job.setHours(new: (hours-1)) job.setMins(new: 59) } if job.seconds == 0 && secsDone == false{ job.setMins(new: (mins-1)) job.setSeconds(new: 59) } if hours == 0 && minsDone == true && secsDone == true { workTimeActive = false //stopTimer() } else { job.setSeconds(new: job.seconds-1) } if manager.isGyroActive == false {print("not active tag 3")} currentTimeRemaining = dispTime(mustRedo: mustRedo) private func keepScreenOn() { UIApplication.shared.isIdleTimerDisabled = true } private func shouldProceed() -> Bool{ if faceUp == true { if manager.isGyroActive == false {print("not active tag 4")} return false } return true }
Posted
by
Post not yet marked as solved
0 Replies
296 Views
I cannot get CMMotionActivityManager.startActivityUpdates() to work. I have given my app permission to use core motion and also put the required description key into my Info.plist file. I am expecting my user to walk. I call startActivityUpdates() and then stand up and start walking. I typically get about 3 callbacks within a couple of seconds, all of which have "false" set for all of the activity flags, even "unknown". Then after that I get nothing. I can't figure out what I could possibly be doing wrong here. The code is really simple. I looked at doezens of examples and my code is doing the exact same things.
Posted
by
Post not yet marked as solved
1 Replies
377 Views
I'm working on a screen where the goal is for the user to walk for 6 minutes while the app times them and measures the distance walked. I'm using CMPedometer to track the walking distance and a repeating 1-second Timer to count down the time. This works fine as long as the app is in the foreground, but I'd like my user to be able to lock their phone and put it away while they walk. I used UIApplication.shared.beginBackgroundTask, but it doesn't provide enough time. It usually only gives me around 30 seconds. I also tried calling UIApplication.shared.beginBackgroundTask again or calling it once every time the timer ticks, with no better result. How can I accomplish my goal here?
Posted
by
Post not yet marked as solved
3 Replies
356 Views
I'm not getting any values from the floorsAscended or floorsDescended properties of CMPedometerData. I tested it by walking up and down a flight of stairs twice while monitoring for pedometer updates for 60 seconds. I also queried for the pedometer data separately at the end of the time period in case there were any updates I missed. I'm using an iPhone 13 pro for my tests and I did check to make sure CMPedometer.isFloorCountingAvailable() is true, and I am getting other kinds of pedometer data such as distance, pace, and steps. Is there something else I need to do in order to enable floor counting? Thanks, Frank
Posted
by
Post not yet marked as solved
0 Replies
299 Views
I'm trying to use CMAcceleration data in my app to detect when the user is doing certain kinds of activities. The problem I'm having is that the acceleration data for the same user motions is different depending on how they are holding their phone. I don't care about the orientation of the phone, I just care about the overall motion of the person holding it. I've researched and tried a whole bunch of ways to correct the data for phone orientation, such as rotating the acceleration using the CMAttitude rotation matrix, removing the effect of gravity with a series of calculations, and doing both of these in both orders. I can't seem to come up with something that works. I think there has to be some solution since iOS can do things like step counting which I assume doesn't depend on the orientation of the phone. Thanks, Frank
Posted
by
Post not yet marked as solved
0 Replies
169 Views
how could I remove the key NSMotionUsageDescription? cause it leads some crash problem.But after I remove the key NSMotionUsageDescription, I submit to Apple Store connect,I will receive issue .TMS-90683: Missing purpose string in Info.plist - Your app’s code references one or more APIs that access sensitive user data, or the app has one or more entitlements that permit such access. The Info.plist file for the “ydbus.app” bundle should contain a NSMotionUsageDescription key with a user-facing purpose string explaining clearly and completely why your app needs the data. If you’re using external libraries or SDKs, they may reference APIs that require a purpose string. While your app might not use these APIs, a purpose string is still required. For details, visit: https://developer.apple.com/documentation/uikit/protecting_the_user_s_privacy/requesting_access_to_protected_resources. How could I solve the problem? I reviewed my project,I don't use the key NSMotionUsageDescription api.
Posted
by
Post not yet marked as solved
2 Replies
133 Views
I am writing a bachelor thesis and I have to know which accelerometer chip is used in iPhone 12, 14 and 15, but I cannot find any information regarding that. I found out in an article that the original iPhone uses LIS302DL, but iPhone 3G and 4 uses LIS331DL.
Posted
by
Post not yet marked as solved
4 Replies
168 Views
Our watchOS app uses CMFallDetectionManager (with the proper entitlement) to help alert our users and their caregivers when a fall occurs. We have had a simple implementation in our app for a couple of years now and it seems to work fine. Recently, we received a report of delayed fall alerts and have traced back the root cause to a failure from the system to call func fallDetectionManager(_ fallDetectionManager: CMFallDetectionManager, didDetect event: CMFallDetectionEvent, completionHandler handler: @escaping () -> Void) promptly when a fall occurs. Our implementation of this method begins with the following logging statement: "Fall detected at \(event.date) with status \(event.resolution.rawValue) at \(Date())" When we check our logs, we see a number of events that occur as expected, for example: Fall detected at DATE_AND_HOURS:42:09 +0000 with status 1 at DATE_AND_HOURS:42:51 +0000 However, many events show a period of several minutes from fall detection to a report: Fall detected at DATE_AND_HOURS:28:09 +0000 with status 0 at DATE_AND_HOURS:32:42 +0000 or Fall detected at DATE_AND_HOURS:44:26 +0000 with status 1 at DATE_AND_HOURS:48:14 +0000 And in the instance from our customer, we had a fall detected that evidently wasn't reported for 5 hours and 4 minutes (I'm not sharing exact timestamps publicly to maintain user privacy). We are aware of the documentation regarding the delegate and have programmed it appropriately not to receive duplicate events: Additionally, each time the user launches your app, the system checks to see if a fall event has occurred during the recent past. If one has occurred, it calls this method. Note that your app may receive the same event multiple times, for example, if the app crashes and relaunches. Always check the event’s date property to determine whether your app has already received the event. The system guarantees that different fall events have different date values. Moreover, our logger persists logs when there is no network access, and the delegate callback also requests a network post to our servers that, again, is preserved in a background queue until connectivity is restored if it's not available. Our app's other updates (watchOS complication, etc.) from this user's Watch also show that our app was running in the background and communicating with our servers during that time. We have very high confidence that the watch and our app did not miss any more timely calls to that delegate method. While this one five-hour delay was an exceptionally bad occurrence, we also find the other delays of several minutes to be concerning, considering the time-sensitive nature of falls. Does Apple or do any developers have any insights about what's going on and what expectations we should be setting for our users?
Posted
by
Post not yet marked as solved
1 Replies
80 Views
Reproducible on iOS 17.4.1 (maybe before) & iOS 17.5. Maybe iOS 17.4 but I can't test it. NSMotionUsageDescription is correctly set (and has always been) Fitness activity & motion authorization are correctly enabled The delivery for absolute altitude changes became super slow, and might be inaccurate. The only value I get is exactly the same as the GPS altitude. The accelerometer data does not seem to be taken into account anymore. This critical bug has broken two apps of mine. How could I quickly solve this? Thank you! PS: code is dead simple let operationQueue = OperationQueue() self.altimeter.startAbsoluteAltitudeUpdates(to: operationQueue) { [weak self] (data, error) in guard let self = self else { return } guard let data else { return } DispatchQueue.main.async { // Use this value for display self.altitude = Measurement(value: data.altitude, unit: UnitLength.meters) /* DEBUG VIEW */ self.updateDebugView(with: data.altitude) } }
Posted
by