I learned objective c myself and haven't taken any courses for it. Hence, some times I get confused with minor things while writing iOS app. This question may be very lame, but I could not find any solution or I could not understand the solution. Here is my situation:
My app contains single view controller (the default one). I want to get continuous values from accelerometer, gyroscope and magnetometer and use the values to estimate user location using pedestrian dead reckoning (PDR). For this purpose, I used CoreMotion and made a CLMotionManager (motionManager
) property in header file. Using this manager, I can check whether the sensors are available and get their values, for example:
if([_motionManager isAccelerometerAvailable])
{
_motionManager.accelerometerUpdateInterval = 0.1;
[_motionManager startAccelerometerUpdatesToQueue:[[NSOperationQueue alloc]init] withHandler:^(CMAccelerometerData * _Nullable accelerometerData, NSError * _Nullable error) {
x=accelerometerData.acceleration.x;
y = accelerometerData.acceleration.y;
z = accelerometerData.acceleration.z;
}];}
Similarly, I can get values from gyroscope and magnetometer. I get these values inside a IBAction
method after pressing a button as:
-(IBAction)startSensor:(id)sender
{
//Getting accelerometer, gyroscope, and magnetometer values.
}
The PDR operation happens in my next method as:
-(void)thePDROperationWith:(NSArray*)accelerometerValues gyroscopeValues:(NSArray*)gyros magnetometerValues:(NSArray*)magneto
{
//The PDR operations with accelerometer, gyroscope and magnetometer values
}
Now, my question is:
1) How to get continuous PDR operation value from thePDROperationWith::
method? I called this method inside the startSensor
method, however I
get the value just once when I press the button. Moreover, am I supposed
to declare this method in header file too (as in user defined NSObject
subclass)?
2) What is the difference between user defined method and delegate methods like
//a method in CLBeaconManager delegate
-(void)beaconManager:(CLBeaconManager*)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{
//code
}
?
This delegate method (I expect I am using the correct term) runs continuously to range the beacons in the defined CLBeaconRegion
. How can I make such method for my purpose?
Thank you.