我可以在Swift Playgroundbooks中使用CoreMotion吗?

时间:2019-03-27 16:36:46

标签: swift swift-playground core-motion

以下代码在Swift Playground(即.playground文件)中可以正确执行,并显示设备的加速度。似乎支持Core Motion!

import CoreMotion

class MyMotion {
    var motionManager: CMMotionManager!
    init() {
        motionManager = CMMotionManager()
        motionManager.startAccelerometerUpdates()
    }
}

let motion = MyMotion()
if let accelerometerData = motion.motionManager.accelerometerData {
    print(accelerometerData)
} else {
    print("Core Motion usage failed")
}

不幸的是,当放在.playgroundbook页面中时,此代码不起作用。

  

Core Motion使用失败

是否可以将CoreMotion框架集成到Playgroundbook中?

0 个答案:

没有答案
相关问题