我想通过 PyObjC 访问我 iPhone 的加速度计。这是我的代码:
@objc.signature("v@:@@")
def accelerometer_didAccelerate_(self, accelerometer, acceleration):
msgBox = UIAlertView.alloc().initWithTitle_message_delegate_cancelButtonTitle_otherButtonTitles_("Acceleration", str(acceleration.x), self, "OK", None)
msgBox.show()
msgBox.release()
@objc.signature("v@:@")
def applicationDidFinishLaunching_(self, unused):
self.accelerometer = UIAccelerometer.sharedAccelerometer()
self.accelerometer.setUpdateInterval_(1)
self.accelerometer.setDelegate_(self)
#...
问题是 str(accelleration.x) 返回"<native-selector x of <UIAcceleration: 0x.....>>"
。我能做些什么?