Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 在CoreLocation中使用新的CLVisit_Swift_Core Location_Ios8 - Fatal编程技术网

Swift 在CoreLocation中使用新的CLVisit

Swift 在CoreLocation中使用新的CLVisit,swift,core-location,ios8,Swift,Core Location,Ios8,我没有发现任何关于CLVisit的内容,所以我正在尝试自己探索这项技术 有人知道它为什么不起作用吗? 所有.plist键都已设置并工作 class ViewController: UIViewController,CLLocationManagerDelegate { var manager:CLLocationManager! override func viewDidLoad() { super.viewDidLoad() // Do any additional set

我没有发现任何关于CLVisit的内容,所以我正在尝试自己探索这项技术

有人知道它为什么不起作用吗? 所有.plist键都已设置并工作

class ViewController: UIViewController,CLLocationManagerDelegate {

var manager:CLLocationManager!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    manager = CLLocationManager()
    manager.delegate = self
    manager.desiredAccuracy = kCLLocationAccuracyBest
    manager.requestAlwaysAuthorization()
    manager.startMonitoringVisits()


}


func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {

}
func locationManager(manager: CLLocationManager!,
    didVisit visit: CLVisit!)
{
    println("visit: \(visit.coordinate.latitude),\(visit.coordinate.longitude)")
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


}

您的代码看起来是正确的。我还发现CLVisit并没有按照我理解的方式工作。调试起来很棘手,因为您实际上必须离开工作区才能对其进行测试。:)

CLVisit用于确定“访问”的启发式方法没有记录,但根据WWDC视频,在CLVisit确定您正在访问而不仅仅是路过之前,您必须停留一段未指定的时间。我获得代理回调的成功非常有限。一次arrivalDate访问在一个地点大约两分钟后启动,另一次大约十分钟后启动,但大多数情况下从未启动过访问

如果您外出走动,NSLog无法捕获CLV访问,因此我设置了一个简单的核心数据实体,并记录所有访问:

    Visits *thisVisit = [NSEntityDescription insertNewObjectForEntityForName:@"Visits" inManagedObjectContext:[self managedObjectContext]];
    thisVisit.arrivalDate = visit.arrivalDate;
    thisVisit.departureDate = visit.departureDate;
    thisVisit.latitude = [NSNumber numberWithDouble:visit.coordinate.latitude];
    thisVisit.longitude = [NSNumber numberWithDouble:visit.coordinate.longitude];
    [self saveContext];
即使我的设备已经在家里放置了好几个小时,当我离开或返回时,我也不会一直收到到达或离开事件

编辑:这是一个完整的示例。安装并使用几天,您将看到这个新API的问题。我希望它在以后的Beta中工作得更好。 对我来说,这仍然是相当不一致的-有时连续两次到达,有时连续两次离开,在访问前的长时间延迟


我假设您试图在应用程序处于后台时获取这些委托调用;但是,您正在视图控制器中实例化CLLocationManager,该视图控制器将不会被实例化(afaik)

这对我来说很有用(我在第二代iPad mini上使用iOS 8 beta 2):设置
NSLocationAlwaysUsageDescription
键,在Capabilities中启用“位置更新”后台模式,并在
AppDelegate
中包含以下内容:

let locationManager = CLLocationManager()

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
    locationManager.delegate = self
    locationManager.requestAlwaysAuthorization()
    locationManager.startMonitoringVisits()

    return true
}

func locationManager(manager: CLLocationManager!, didVisit visit: CLVisit!) {
    println("Visit: \(visit)")
    // I find that sending this to a UILocalNotification is handy for debugging
}

更新:我推送了一个示例应用程序,它可以工作。

我开始认为这个API有一个服务器组件。我的测试应用确实是在AppDelegate中设置的,在没有代码更改的情况下,它就在最近几天内开始间歇性地启动访问。但它忽略了一些,似乎创造了另一些

下面是我的应用程序记录的最近两次访问。这些点基本相同(相距约30英尺)。我认为第一次到达是准确的,但出发是不准确的。第二次访问完全没有发生。我的测试设备在那段时间没有离开家

纬度:xx.11852879438132 经度:-xxx.7792256808099 到达日期:2014-06-25下午12:19 出发日期:2014-06-25下午4:44

纬度:xx.1185726857039 经度:-xxx.7793685278068 到达日期:2014-06-26上午5:59 出发日期:遥远的未来


早些时候,我把它拿了出来,大约有好几次,只是偶尔有人访问fire。

所以ClVisit很有问题,我们应该等待第三次测试。。。我在两个地方呆了1个多小时,没有任何标记(我使用NSUserdefaults来存储访问。我使用beta 2,并可靠地收到通知。在我的(有限的)经验,出发通知是比较接近的,所以人们经常只在离开某个特定地点通知访问。在这个装置上为我工作。我不知道如何在模拟器TBHOK中测试这个,不能让CLLocationManager在Beta 2设备上为我工作。尝试所有的建议。我已经添加了一个演示应用程序-也许可以看看它是否适合你?如果苹果能给我们一种模拟CLV访问的方法,那就太好了,这样我们就可以不用开车在城里转转就可以进行测试了。有人对模拟这些访问有想法吗?我在考虑使用GPX文件。。但不知道硬件将如何选择访问。一次访问需要多长时间才能被认定为CLVisit@姆洛伦,请给我解释一下。当您测试github项目时,您在特定位置停留了多长时间?当应用程序被关闭时,这是否也起作用??