Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

man2manno

macrumors member
Original poster
Mar 21, 2009
55
0
Hey guys, still somewhat new at this so I could use a little help. I am trying to get the accelerometer to work in a class i created ("myclass"). I put the following code in my applicationDidFinishLauching method in my appDelegate:

[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 60.0f)];
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
NSLog(@"Accelerometer configured and started");

Then I put the following code under it:
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate: (UIAcceleration *)acceleration
{

if ([acceleration x] >=2 || [acceleration y] >=2 || [acceleration z] >=2)
{
NSLog(@"X=%f Y=%f Z=%f", [acceleration x], [acceleration y], [acceleration z]);
}
}

That all works perfectly...my question is how do I get that to work in a class that I created?

Thanks
 

BlackWolf

macrumors regular
Apr 9, 2009
244
0
I don't even understand the question :D
you set a delegate. the messages the Accelerometer sends are sent to that delegate. if you need to receive accelerations in a class you created, then set an instance of that class as the delegate of the accelerometer - or, much more simple, execute the exact code you posted when the instance of your class is created (in the init method)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.