Via How to access motion & orientation information of remote:
Trước hết, chúng ta cần sử dụng NSNotificationCenter
để tìm ra bộ điều khiển. Có lẽ tốt nhất để làm điều này khi ứng dụng khởi chạy. Một cái gì đó như thế này:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(controllerDidConnect:) name:GCControllerDidConnectNotification object:nil];
Sau đó chúng tôi có thể sử dụng đoạn mã sau sau khi kết nối để lưu trữ các thông tin thiết bị trong một tài sản:
- (void)controllerDidConnect:(NSNotification *)notification {
self.myController = notification.object;
}
Các hồ sơ từ xa là một lớp con của hồ sơ gamepad vi. Motion và các dữ liệu khác có thể được theo dõi bằng cách thêm một giá trị thay đổi xử lý sự kiện:
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);
}
};
Nguồn
2015-09-29 12:32:24
Bạn đã nhận được một bộ dev về thể chất hoặc bạn đang sử dụng trình giả lập? –
Bộ vật lý – CodyMace
Đây là một bài viết từ diễn đàn Nhà phát triển ứng dụng về điều này: https://forums.developer.apple.com/thread/18861 – Stefan