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