Via How to access information about movement and orientation of a remote :
First of all, you need to use NSNotificationCenter to search for controllers. It is probably best to do this when the application starts. Something like that:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerDidConnect:) name:GCControllerDidConnectNotification object:nil];
Then we can use the following code after connecting to store information about the device in the property:
- (void)controllerDidConnect:(NSNotification *)notification { self.myController = notification.object; }
The remote profile is a subclass of the micro-controller profile. You can track movement and other data by adding an event handler value:
GCMicroGamepad *profile = self.myController.microGamepad profile.valueChangedHandler= ^ (GCMicroGamepad *gamepad, GCControllerElement *element) { if (self.myController.motion) { NSLog(@"motion supported"); NSLog(@"gravity: %f %f %f", self.myController.motion.gravity.x, self.myController.motion.gravity.y, self.myController.motion.gravity.z); NSLog(@"userAcc: %f %f %f", self.myController.motion.userAcceleration.x, self.myController.motion.userAcceleration.y, self.myController.motion.userAcceleration.z); NSLog(@"rotationRate: %f %f %f", self.myController.motion.rotationRate.x, self.myController.motion.rotationRate.y, self.myController.motion.rotationRate.z); NSLog(@"attitude: %f %f %f %f", self.myController.motion.attitude.x, self.myController.motion.attitude.y, self.myController.motion.attitude.z, self.myController.motion.attitude.w); } };
source share