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);
}
谢谢。
Can anyone please let me know if it is possible to handle events like OrientationChanged, Shake, LocationChanged etc.. when my App running in background?
I have tried following code but it gets invoked only when my app running in foreground!
- (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);
}
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://developer.apple.com/ library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html
您应该在您的info.plist 文件位于 UIRequiredDeviceCapability 键下
,那么您的应用将在后台接收位置更新。
然而,这会以更快的速度耗尽电池..无需用户了解太多..如果可能的话,您应该仅注册重要位置
方向更改的更新将无法在后台进行。
摇晃可能是……我不确定
http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html
You should include location-services in your info.plist file under the key UIRequiredDeviceCapabilities
then your app will receive location updates in the background.
However this drains the battery at a faster rate..without user knowing much..If possible you should register for only significant location
orientation changed updates won't be possible in background.
shake might be..i am not sure