Core Motion

RSS for tag

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

Posts under Core Motion tag

36 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

App crashes with error "SIGNAL 6:Abort trap:6"
The application crashes and displays the error "SIGNAL 6:Abort trap:6" while it is in movement. We have implemented telematics functionality, which required us to add permissions for location, motion, and bluetooth. We have attached the log file. Help us to resolve this Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Exception Reason: -[%s %s]: unrecognized selector sent to instance 0x303475170 Termination Reason: SIGNAL 6 Abort trap: 6 Triggered by Thread: 6 Last Exception Backtrace: 0 CoreFoundation 0x1a6594f20 __exceptionPreprocess + 164 (NSException.m:249) 1 libobjc.A.dylib 0x19e426018 objc_exception_throw + 60 (objc-exception.mm:356) 2 CoreFoundation 0x1a669e480 -[NSObject(NSObject) doesNotRecognizeSelector:] + 344 (NSObject.m:161) 3 CoreFoundation 0x1a6531fb4 forwarding + 1572 (NSForwarding.m:3612) 4 CoreFoundation 0x1a65318d0 CF_forwarding_prep_0 + 96 (:-1) 5 Boubyan Takaful Insurance 0x1045199fc -[MendixEncryptedStorageModule getItem:resolver:rejecter:] + 456 (MendixEncryptedStorageModule.m:93) 6 CoreFoundation 0x1a6531814 invoking + 148 (:-1) 7 CoreFoundation 0x1a6530860 -[NSInvocation invoke] + 428 (NSForwarding.m:3411) 8 CoreFoundation 0x1a65a71dc -[NSInvocation invokeWithTarget:] + 64 (NSForwarding.m:3508) 9 Boubyan Takaful Insurance 0x1041fc6fc -[RCTModuleMethod invokeWithBridge:module:arguments:] + 388 (RCTModuleMethod.mm:584) 10 Boubyan Takaful Insurance 0x1041fe6e0 facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&, int, (anonymous namespace)::SchedulingContext) + 452 (RCTNativeModule.mm:183) 11 Boubyan Takaful Insurance 0x1041fe330 facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)::$_0::operator()() const + 68 (RCTNativeModule.mm:104) 12 Boubyan Takaful Insurance 0x1041fe330 invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int) + 112 (RCTNativeModule.mm:95) 13 libdispatch.dylib 0x1ae43813c _dispatch_call_block_and_release + 32 (init.c:1530) 14 libdispatch.dylib 0x1ae439dd4 _dispatch_client_callout + 20 (object.m:576) 15 libdispatch.dylib 0x1ae441400 _dispatch_lane_serial_drain + 748 (queue.c:3900) 16 libdispatch.dylib 0x1ae441f30 _dispatch_lane_invoke + 380 (queue.c:3991) 17 libdispatch.dylib 0x1ae44ccb4 _dispatch_root_queue_drain_deferred_wlh + 288 (queue.c:6998) 18 libdispatch.dylib 0x1ae44c528 _dispatch_workloop_worker_thread + 404 (queue.c:6592) 19 libsystem_pthread.dylib 0x2033eb934 _pthread_wqthread + 288 (pthread.c:2696) 20 libsystem_pthread.dylib 0x2033e80cc start_wqthread + 8 (:-1) hread 6 crashed with ARM Thread State (64-bit): x0: 0x0000000000000000 x1: 0x0000000000000000 x2: 0x0000000000000000 x3: 0x0000000000000000 x4: 0x00000002033112c3 x5: 0x000000016c0aa810 x6: 0x000000000000006e x7: 0x0000000000000000 x8: 0xe50a98ccb19cbcdd x9: 0xe50a98cddd960cdd x10: 0x0000000000000200 x11: 0x000000016c0aa340 x12: 0x0000000000000000 x13: 0x00000000001ff800 x14: 0x0000000000000010 x15: 0x0000000000000000 x16: 0x0000000000000148 x17: 0x000000016c0ab000 x18: 0x0000000000000000 x19: 0x0000000000000006 x20: 0x0000000000002403 x21: 0x000000016c0ab0e0 x22: 0x0000000000000114 x23: 0x000000016c0ab0e0 x24: 0x0000000301846ee8 x25: 0x0000000000000000 x26: 0x0000000000000000 x27: 0x0000000302354e00 x28: 0x0000000000000000 fp: 0x000000016c0aa780 lr: 0x00000002033eec0c sp: 0x000000016c0aa760 pc: 0x00000001ef64f42c cpsr: 0x40001000 esr: 0x56000080 Address size fault crashlog.crash
1
0
22
16h
How to use CMHighFrequencyHeartRateData to read the Heart rate data from CoreMotion framework
Hello, As per Apple Documentation Link for CoreMotion framework we can read high frequency heart rate using CMHighFrequencyHeartRateData but there is No way to set the type like heartRate and have a updateHandler to provide the heart rate data. But for Accelerometer data, CoreMotion framework can provide startAccelerometerUpdates(to:, withHandler:) and user can set update interval like accelerometerUpdateInterval using CMMotionManager. But There is no solution available for heartRate. If any solution is available to read heartRate using CMHighFrequencyHeartRateData it will be helpful for me. I know we can read the Heart Rate Data using HealthKit framework using HKAnchoredObjectQuery but the heart rate data is not consistent and startDate & endDate for heart rate data is also not consistent. We want heart rate very frequent like every second. Any help can be appreciated. Thanks in advance
1
0
160
2w
How to get permissions to Motion & Fitness
I am trying to access the CMAltimeter class, and I keep getting the error Domain=CMErrorDomain Code=105. I know that indicates my app does not have permissions for motion and fitness. All the documentation I can find mentions the need to add NSMotionUsageDescription to Info.plist. However, I have done that, and it does not help. I am using Xcode 15. It seems that whenever I go to look up how to get permissions to something, the information on the web seems to be outdated, and Apple seems to move stuff around. I have found I can add the entry to Info.plist by using the Info.plist editor and selecting "Privacy - Motion Usage Description", but that does not help. I also notice that when I info tab on my build target, there is a "Privacy - Motion Usage Description" there also. If I add the entry there, it takes out out of my Info.plist, and makes an entry in the project's project.pbxproj file named INFOPLIST_KEY_NSMotionUsageDescription. Regardless of which of those I use, I still do not the 105 error. I'm sure I'm missing something more, but I can't find it anywhere. There was mention of a "Health and Fitness" in the signing capabilities, but I could not find anything listed there in Xcode 15
3
0
241
3w
CMAltimeter absolute altitude delivery BROKEN (super slow & inaccurate)
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) } }
2
0
295
4w
Delayed reports from CMFallDetectionManager
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?
9
0
456
May ’24
Accelerometer devices
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.
2
0
247
Apr ’24
how could I remove the key NSMotionUsageDescription? cause it leads some crash problem.
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.
0
0
284
Apr ’24
Rotating or normalizing CMAcceleration data
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
0
0
391
Mar ’24
CMPedometer not counting floors
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
3
0
471
Mar ’24
My background task needs more time
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?
1
0
505
Mar ’24
CMMotionActivityManager.startActivityUpdates() is not working
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.
0
0
389
Mar ’24
CMMotionManager stops sending gyro updates without calling stopGyroUpdates
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 }
0
0
303
Feb ’24
Debugging of CMWaterSubmersionManager
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
0
0
408
Feb ’24
Pedometer updates frequency
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 :)
1
0
411
Feb ’24
I need some general Core Motion advice
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.
0
0
385
Feb ’24
statusInfo field in CMAbsoluteAltitudeData
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!
0
0
374
Jan ’24
Double value cannot be converted to UInt8 because the result would be less than UInt8.min
I have a swift callback function that accumulates data from the gyroscope handler CMGyroData to value, and takes care that it never goes below zero. Any thoughts why I got this crash? var value: Double = 90 func test(d: Double) { value -= d if value < 0 { value = 0 } else if value > 180 { value = 180 } // Double value cannot be converted to UInt8 because the result would be less than UInt8.min // according to Xcode, value is 0 let angle = UInt8(value.rounded()) print(angle) } During the crash, the debugger shows that value is 0, and the raw memory is 0x0000000000000000. I've heard about negative zero, but then the raw memory would be 0x8000000000000000. Either way, it makes no sense for the UInt8 constructor to fail. (lldb) p value (Double) 0 (lldb) p value.rounded() (Double) 0 (lldb) p UInt8(value.rounded()) (UInt8) 0 Xcode 15.1, iPhone 7 Plus, iOS 15.8 Edit: As a good measure, I changed that line to let angle = UInt8(Int(value.rounded()))
7
0
912
Dec ’23
CoreMotion and movement WatchOS
Hello everyone, I'm coming to you because I'm having a little trouble finding the code to know the movement of the Apple Watch. I try to know exactly when the arm movement is up, down, left or right. I can define it thanks to “attitude.pitch” I can define it using "attitude", but it doesn't work correctly when the wrist is rotating at the same time as an arm movement. I no longer know how to move forward to know each movement. My code is as follows: (attitudeAvant11 is the attitude to the forward scan) (attitude11 is the attitude.pitch on the AppleWatch) Thank for your help func knowMove (attitude11:Double, attitudeAvant11:Double) -> (Sens2:String, attitudeAvant12:Double) { var attitude1 = attitude11 attitude1 = attitude1 * 100 let pourcentage = attitude1 - attitudeAvant if attitudeAvant != 0 { if pourcentage >= 0.5 { sensPrint = "Sens: Move down // ➡️\(pourcentage) ⬅️ // \(attitude1) // \(attitudeAvant)" sens1 = "1" } else { if pourcentage < -1.2 { sensPrint = "Sens: Move Up // ➡️\(pourcentage)⬅️ // \(attitude1) // \(attitudeAvant)" sens1 = "2" } else { sensPrint = "Sens: No Move // ➡️\(pourcentage)⬅️ // \(attitude1) // \(attitudeAvant)" sens1 = "0" } } } else { sensPrint = "Sens: No Move Initialisation // ➡️\(pourcentage)⬅️ // \(attitude1) // \(attitudeAvant) " } let DateMaintenant = Date() let formatter = DateFormatter() formatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS" let dateString = formatter.string(from: DateMaintenant) if sens1 != "Nul" { TableauAttitude["\(dateString)"] = "\(sens1)" //print(TableauAttitude) } attitudeAvant = attitude1 print("sensPrint: \(sensPrint)") return (sens1,attitudeAvant) }
0
0
508
Dec ’23