iPhone:当应用程序在后台运行时捕捉事件



当我的应用程序在后台运行时,有人能告诉我是否可以处理OrientationChanged、Shake、LocationChanged等事件吗?

我尝试过以下代码,但只有当我的应用程序在前台运行时,它才会被调用!

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
//if the time interval returned from core location is more than two minutes we ignore it because it might be from an old session
if ( abs([newLocation.timestamp timeIntervalSinceDate: [NSDate date]]) < 120) {     
    self.currentLocation = newLocation;
}
NSLog(@"lat: %f long:%f",currentLocation.coordinate.latitude,currentLocation.coordinate.longitude);
}

谢谢。

http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html

您应该在info.plist文件中的UIRequiredDeviceCapabilities键下包含定位服务

然后你的应用程序将在后台接收位置更新。然而,这会以更快的速度消耗电池。。而用户不知道太多。。如果可能,您应该只注册重要位置

方向更改后的更新将无法在后台进行。抖动可能是..我不确定

最新更新