2

I have two different POC, one for the accelerometer and one for GPS. However, I am not comprehending the architecture to put marry both of the applications. I need to initialize both the accel and GPS when the application loads. I have the main view tied to the accel, but also need to the the location of the device.

My current architecture is Projects in workspace

  • Main App
  • Utility App
  • Services App
  • Domain App

The main app ViewController inherits

: UIViewController

That all wires up correctly the the accel works as expected.

In the Utility CoreLocationUtility class, I have it inheriting the CLLocationManagerDelegate.

The question is, how do I register a delegate from the same view that is of type AccelDelegate?

1 Answers1

0

If you want to make your ViewController act as delegate for both accelerometer and GPS, state in its header file that it obeys both delegate protocols:

@interface ViewController : UIViewController <CLLocationManagerDelegate, UIAccelerometerDelegate> {
    CLLocationManager *myLocationManager; // an instance variable
}
 // ... your definitions
@end

then somewhere in your ViewController

[UIAccelerometer sharedAccelerometer].delegate = self;
myLocationManager = [[CLLocationManager alloc] init];
myLocationManager.delegate = self;

then somewhere else in your ViewController, put the delegate methods for both protocols

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
    // ... your code
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
   // ... your code

}

and that should work, although there may be typos, I have not compiled this. Plus, in my experience, location manager code tends to get quite big. You may be much better off putting it in a class of its own, to be instantiated by the ViewController.

Can anyone explain why the only method in the UIAccelerometerDelegate protocol is deprecated?

emrys57
  • 6,679
  • 3
  • 39
  • 49
  • The protocol is dperectaed because you shoul duse CoreMotion instead: see http://stackoverflow.com/questions/6742531/why-is-accelerometerdidaccelerate-deprecated-in-ios5 – AlexWien Dec 01 '12 at 19:18
  • Thanks! I've never used the accelerometer, I will file that away for later. – emrys57 Dec 01 '12 at 22:13