0
我正在编写一个应用程序,每次手机移动时都必须进行一些计算。我已经阅读过每个问题,但无法让Accelerometer在后台收集数据(在用户离开应用程序之后)。我在Plist.info
中设置了Location updates
标志。这是我使用的代码:在后台收集加速计数据
let motionManager = CMMotionManager()
func startMotionUpdates() {
var timestamps = [NSDate]()
if motionManager.accelerometerAvailable {
motionManager.accelerometerUpdateInterval = 1
motionManager.startAccelerometerUpdatesToQueue(NSOperationQueue(), withHandler: { (data: CMAccelerometerData?, error: NSError?) -> Void in
dispatch_async(dispatch_get_main_queue(), {() -> Void in
let time = NSDate(timeIntervalSince1970: data!.timestamp)
timestamps.append(time)
print(timestamps)
})
})
}
}
我想尽组合在那里,我已经使用CMDeviceMotion
试过,我一直在使用CLLocationManager.startUpdatingLocation()
模拟背景活动试过,但没有任何工程。有人有任何想法吗?
每次用户改变位置或开始移动时,我都需要知道。你说我会被唤醒,当位置改变了几米时,但是'startMonitoringSignificantLocationChanges'的文档指出,它实际上是500或更多,这对我不起作用。有没有其他方法可以做到这一点? – smeshko