0

I am porting my android App to iOS, and have a little trouble with accelerometer. I want to have two different classes, that have DidAccelerate implementation. I make two objects, each becomes a delegate for UIAccelerometer. But only one object - that was created last, works. The other one do not get event from accelerometer. UIAccelerometer can not have two delegates working in the same time in one application?

Maep
  • 833
  • 1
  • 10
  • 16

2 Answers2

1

I would make your view controller the main delegate for the accelerometer and then have that implementation pass the data on to any other concerned parties:

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {

    /* So just create a couple properties to hold an instance of your other delegates. */
    [self.accelerometerDelegate1 accelerometer:accelerometer didAccelerate:acceleration];

    [self.accelerometerDelegate2 accelerometer:accelerometer didAccelerate:acceleration];
}
jerrylroberts
  • 3,419
  • 23
  • 22
0

You might want to use a singleton for that.

jimpic
  • 5,360
  • 2
  • 28
  • 37