iOS Tutorial Monitor the device attitude (orientation) and acceleration with Motion object

Andris

Active Member
Licensed User
Does it work with the code I posted?
Erel, the code you posted there works fine to return magnetometer data, and the reference frame can be changed OK. But to get attitude info (yaw, roll, pitch), I need to add the call to the CMAttitude class, but I have some kind of mistake that makes it fail after upload:
B4X:
#if OBJC

- (void)startMotion:(CMMotionManager*)manager {
   [manager startDeviceMotionUpdatesUsingReferenceFrame: CMAttitudeReferenceFrameXMagneticNorthZVertical];
}

- (NSArray*) GetCorrectedAttitude:(CMMotionManager*)manager {
   CMAttitude catt = manager.deviceMotion.attitude;
   return @[@(catt.yaw), @(catt.roll), @(catt.pitch)];
}
#End If
 

Erel

Administrator
Staff member
Licensed User
You only need:
B4X:
Sub Page1_BarButtonClick (Tag As String)
   If Tag = "Start" Then
       timer1.Enabled = True
       Dim no As NativeObject = Me
       no.RunMethod("startMotion:", Array(mot))
   Else
       timer1.Enabled = False
       mot.Stop
   End If
   bbStart.Enabled = Not(timer1.Enabled)
   bbStop.Enabled = timer1.Enabled
End Sub

#if OBJC

- (void)startMotion:(CMMotionManager*)manager {
   [manager startDeviceMotionUpdatesUsingReferenceFrame: CMAttitudeReferenceFrameXArbitraryCorrectedZVertical];
}
#End If
 
Top