我的應用使用CLLocationManager
跟蹤用戶。在代表電話didUpdateToLocation
我做所有保存他們的立場有趣的東西。但是,我需要一種方法來測試它們是否停止。那我可以停止錄製地點,並考慮他們的旅行結束。所以我在CCLocationManager
中有一個NSTimer
,每調用一次didUpdateToLocation
就會被添加和刪除。當用戶停止並且CLLocationManager
停止呼叫時,它將被啓動。NSTimer和NSRunLoop
我所能得到的NSTimer
工作的唯一方法就是要做到:
[[NSRunLoop mainRunLoop] addTimer:userStoppedMovingTimer forMode:NSRunLoopCommonModes];
然後將其刪除:
[userStoppedMovingTimer invalidate];
我從來沒有在添加計時器這樣過去。有人可以解釋爲什麼這是什麼?
如果使用'+ scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:'創建計時器,則這不應該成爲問題。 – 2012-07-26 01:42:56