Quote:
Originally Posted by baramedia
hello
i wanna get the magnetic field in the device, using this :
@property(readonly, nonatomic) CMCalibratedMagneticField magneticField
so i create my manager motion device :
Code:
motionManager = [[CMMotionManager alloc] init];
referenceAttitude = [motionManager.deviceMotion.attitude retain];
NSLog(@"Boussole Y: %f",motionManager.deviceMotion.magneticField.field.y);
here i get the referenceAttitude, but it give bad access while trying to show the magneticField.field.y !! it seems that the magneticField is not accessible! how is that ??
|
My guess is that when you first create motion manager, the device motion object is nil. (The docs do say that "If no device-motion data is available, the value of this property is nil.") You can send messages to nil objects, but you can't link to records in structures where the pointer to the structure is nil.
Break it down. Create a series of single statements where each statement creates a new local variable and goes one property deeper. Then you examine the contents of each in the debugger, and see exactly which part is failing.
You probably need to add code that checks to see if any of the returned objects is nil, and only continues if you get a non-nil value.
I haven't used this framework before, but I bet you're supposed to create a motion manager, then wait for an update before trying to get motion information.