リモートのモーションと向きの情報にアクセスする方法を介して:
まずNSNotificationCenter
、コントローラーを見つけるために使用する必要があります。おそらく、アプリの起動時にこれを行うのが最善です。このようなもの:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerDidConnect:) name:GCControllerDidConnectNotification object:nil];
接続後に次のコードを使用して、デバイス情報をプロパティに保存できます。
- (void)controllerDidConnect:(NSNotification *)notification {
self.myController = notification.object;
}
リモート プロファイルは、マイクロ ゲームパッド プロファイルのサブクラスです。モーションやその他のデータは、値変更イベント ハンドラーを追加することで追跡できます。
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);
}
};