i am trying to initialize the device motion manager in a class that contains all of my global variables to use in different classes. However i cant seem to get this working.
I have this in my global class:
// Motion Manager
CMMotionManager *motionManager;
Then set the property in a different class header file:
@property (retain) CMMotionManager *motionManager;
And on the .m file i synthetize and start the updates:
@synthesize motionManager;
motionManager = [[CMMotionManager alloc] init];
if (motionManager.deviceMotionAvailable)
{
motionManager.deviceMotionUpdateInterval = 1.0/100.0;
[motionManager startDeviceMotionUpdates];
NSLog(@"Device Started");
}
But when i call this on my third class:
motionManager.deviceMotionAvailable
It returns NO.
PD: both classes import the global class, and the third class imports the second one’s header.
Ok it Seems i can use a singleton class to achieve this:
h file:
m file:
and whenever I want to use it i can just declare a variable in that class header like this:
and use it like this on the m file: