具体来说,我正着眼于后台应用程序收到位置服务更新(重大位置更改)的情况。在这种情况下,背景会发生什么?任何用户代码都可以运行,包括待定计时器吗?NSTimer *上的选择器可以在后台执行吗?
0
A
回答
0
你可以像下面使用后台任务和定时器:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];
return YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
self.bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[[UIApplication sharedApplication] endBackgroundTask:self.bgTask];
self.bgTask = UIBackgroundTaskInvalid;
}];
self.timer = [NSTimer scheduledTimerWithTimeInterval:60
target:self
selector:@selector(changeAccuracy)
userInfo:nil
repeats:YES];
}
- (void) changeAccuracy {
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[self.locationManager setDistanceFilter:kCLDistanceFilterNone];
}
-(void)locationManager:(CLLocationManager *)lm didUpdateLocations:(NSArray *)locations{
CLLocation *location = [locations lastObject];
NSLog(@"Location returned: %f, %f Accuracy: %f", location.coordinate.latitude, location.coordinate.longitude, location.horizontalAccuracy);
[lm setDesiredAccuracy:kCLLocationAccuracyThreeKilometers];
[lm setDistanceFilter:99999];
}
+0
谢谢,但我的问题不是如何实现它与后台任务。我的问题是,定时服务和定时定时器是否会发生(定时器触发)? – 2014-10-12 14:12:24
+0
肯定是的。 Apple允许在后台使用某些特定服务。位置就是其中之一。它可以使用后台任务和计时器来实现。它在https://developer.apple.com/library/ios/documentation/iphone/conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html上有记录 – bllakjakk 2014-10-12 17:22:30
相关问题
- 1. NSTimer在主线程上执行选择器
- 2. 在后台运行NSTimer
- 3. 如何停止在后台执行选择器?
- 4. 在后台执行选择器并获取返回字符串
- 5. 在选择器NSTimer错误
- 6. 如何使用beginBackgrounTaskWithExpirationHandler选择性地指定要在后台执行的操作:
- 7. 我们可以在FROM之后选择表格来执行mySQL CASE吗?
- 8. Android:可以后台活动执行代码吗?
- 9. 在父级上执行选择器NSOperation
- 10. 在单台机器上执行多个Solr碎片可以提高性能吗?
- 11. 我们可以在同一台机器上运行两个不同执行器的gitlab运行器吗?
- 12. 在后台运行NSTimer或UILocalNotification
- 13. React的jQuery选择器可以吗?
- 14. NSTimer未触发选择器
- 15. NSTimer选择器调用
- 16. NSTimer选择器问题
- 17. 值转换器可以在不同的线程上执行吗?
- 18. onclick后可以执行JSP和JAVASCRIPT吗?
- 19. 我可以对同一台服务器执行CURL请求吗?
- 20. NSTimer在后台工作
- 21. 在特定时间执行选择器
- 22. Perl - 你可以在多台机器上运行线程吗?
- 23. 我可以在多台机器上运行F#代理吗?
- 24. Django后台执行器
- 25. XSS可以在服务器上执行吗?
- 26. 在nstimer选择器内比较日期
- 27. 你可以在vim的可视化选择的文本上执行什么?
- 28. 我可以在后台迭代吗?
- 29. 我可以取消在控制台中选择文本吗?
- 30. 我可以在另一个NStimer中使用NStimer吗?
我不这么认为,我觉得只有将被调用外景经理的委托方法,但你为什么不试试吧?测试应该很简单 – Paulw11 2014-10-11 20:03:27
那么你能继续吗? – bllakjakk 2014-10-12 08:46:40
@bllakjakk在下面的链接是我的主要错误,我问这个问题试图了解可能造成它的原因。 http://salesforce.stackexchange.com/questions/51272/sfcrypto-keychain-data-missing-or-corrupted – 2014-10-12 14:07:29