我正在寻找一个开源应用程序或库来跟踪后台的用户位置.现在我正在尝试使用CLLocation和后台任务,但准确性对我的情况来说还不够.你能解释一下,像"移动","管理员","endmondo"等应用程序如何创建我的路线?我应该使用Accelerometer或/和指南针在CLLocation背景点之间创建路线吗?
一些代码:
//location manager init
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.delegate = self;
#pragma mark - CLLocationManager Delegate
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
if ([self isInBackground]) {
if (self.locationUpdatedInBackground) {
bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler: ^{
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
}];
self.locationUpdatedInBackground(newLocation);
[self endBackgroundTask];
}
} else {
if (self.locationUpdatedInForeground) {
self.locationUpdatedInForeground(newLocation);
}
}
}
Run Code Online (Sandbox Code Playgroud)
UPD:Justed使用下一个属性测试了我的应用程序
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.activityType = CLActivityTypeFitness;
self.locationManager.pausesLocationUpdatesAutomatically=NO;
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我在1.5小时旅行期间有大约10个被解雇的事件
我有一个由新的NetworkExtension框架创建的VPN配置应用程序.它工作得很好,但现在我需要添加一些规则才能在我尝试连接到特定URL时转换此VPN.我计划使用NEVPNManager的connectOnDemand功能,但它似乎对我有效.当我在safari中打开http://some-site.com时,我的VPN连接应该建立,但由于某种原因它不会.我尝试了不同类型的配置以及使用生成的.mobileconfig文件来使connectOnDemand工作,但没有运气.它出什么问题了?我正在测试这样的代码:
let manager = NEVPNManager.sharedManager()
manager.enabled = true
manager.loadFromPreferencesWithCompletionHandler { (err) -> Void in
manager.removeFromPreferencesWithCompletionHandler { (err0) -> Void in
print("err0 \(err0)")
print("err \(err)")
let config = NEVPNProtocolIPSec()
config.localIdentifier = "NEVPNProtocolIPSec"
config.remoteIdentifier = "NEVPNProtocolIPSecRemote"
config.disconnectOnSleep = true
config.serverAddress = server
config.authenticationMethod = .Certificate
//configurating here
manager.protocolConfiguration = config
let onDemandRule1 = NEOnDemandRuleConnect()
onDemandRule1.DNSSearchDomainMatch = ["some-site.com", "*.some-site.com"]
manager.onDemandRules = [onDemandRule1]
manager.onDemandEnabled = true
manager.saveToPreferencesWithCompletionHandler({ (err2) -> Void in
print("err2 \(err2)")
})
}
}
Run Code Online (Sandbox Code Playgroud)