Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.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_Swift_Core Location - Fatal编程技术网

Swift 在模拟器中启用CoreLocation

Swift 在模拟器中启用CoreLocation,swift,core-location,Swift,Core Location,didUpdateLocations没有开火 -CLLocationManagerDelegate以viewcontroller作为代理正确实现 import Foundation import UIKit import CoreLocation protocol LocationServiceDelegate { func tracingLocation(currentLocation: CLLocation) func tracingLocationDidFailWithE

didUpdateLocations没有开火 -
CLLocationManagerDelegate
以viewcontroller作为代理正确实现

import Foundation
import UIKit
import CoreLocation

protocol LocationServiceDelegate {
    func tracingLocation(currentLocation: CLLocation)
    func tracingLocationDidFailWithError(error: NSError)
}

class LocationService: NSObject, CLLocationManagerDelegate {

    static var sharedInstance = LocationService()

    var locationManager: CLLocationManager?
    var currentLocation: CLLocation?
    var delegate: LocationServiceDelegate?
    var paymentVC: PaymentViewController?

    override init() {
        super.init()

        self.locationManager = CLLocationManager()
        guard let locationManager = self.locationManager else {
            return
        }

        if CLLocationManager.authorizationStatus() == .notDetermined {
            locationManager.requestAlwaysAuthorization()
        }

        locationManager.distanceFilter = 200

    }

    func startUpdatingLocation() {
        print("Starting Location Updates")
        self.locationManager!.startUpdatingLocation()
    }

    func stopUpdatingLocation() {
        print("Stop Location Updates")
        self.locationManager?.stopUpdatingLocation()
    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

        guard let location = locations.last else {
            return
        }

        self.currentLocation = location
        updateLocation(currentLocation: location)
    }

    private func locationManager(manager: CLLocationManager, didFailWithError error: Error) {
        updateLocationDidFailWithError(error: error as NSError)
    }

    private func updateLocation(currentLocation: CLLocation){
        guard let delegate = self.delegate else {
            return
        }
        delegate.tracingLocation(currentLocation: currentLocation)
    }

    private func updateLocationDidFailWithError(error: NSError) {
        guard let delegate = self.delegate else {
            return
        }
        delegate.tracingLocationDidFailWithError(error: error)
    }
}
  • 这是viewcontroller的扩展,我在其中实现了用于核心位置跟踪的自定义协议
  • 我在viewDidLoad中调用startUpdatingLocations()

    extension PaymentViewController: LocationServiceDelegate,CLLocationManagerDelegate {
    
    func tracingLocation(currentLocation: CLLocation) {
        locationService.currentLocation = currentLocation
    }
    
    func tracingLocationDidFailWithError(error: NSError) {
        print("Error message: \(error.localizedDescription)")
    }
    
    func startUpdatingLocations() {
        locationService.locationManager?.delegate = self
        locationService.delegate = self
        locationService.startUpdatingLocation()
    }
    
    func stopUpdatingLocations() {
        LocationService.sharedInstance.stopUpdatingLocation()
    }
    }
    
corelocation
跟踪未在模拟器中触发。但是,这是启用的


不幸的是,我现在无法使用设备进行测试

我知道在模拟器上模拟核心位置跟踪的唯一方法是选择模拟器调试选项卡中可用的位置选项之一


据我所知,在模拟器上模拟堆芯位置跟踪的唯一方法是选择模拟器调试选项卡中可用的位置选项之一


模拟器不是您的真实设备,因此无法更新您的位置模拟器不是您的真实设备,因此无法更新您的位置