定位服务随机不起作用

时间:2016-07-19 11:57:27

标签: ios swift gps location core-location

苹果定位服务有一个奇怪的问题。 首先,我用来获取用户位置的代码:

import CoreLocation

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate,UISplitViewControllerDelegate,CLLocationManagerDelegate {
    //Core location
    let locationManager = CLLocationManager()

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.

        //Core Location
        // Ask for Authorisation from the User.
        self.locationManager.requestAlwaysAuthorization()

        //Clore Location
        // For use in foreground
        self.locationManager.requestWhenInUseAuthorization()
        if CLLocationManager.locationServicesEnabled() {
            locationManager.delegate = self
            locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
            locationManager.startUpdatingLocation()
        }

        return true
    }

我的info.plist文件:

enter image description here

随机地,当我启动模拟器时,我的应用程序无法获取该位置。通常我将模拟器设备从iphone 6s改为iphone 6,它解决了这个问题。但是今天我已经从一个城市变成了另一个城市,我一直在我的设备中遇到这个问题。我无法得到这个位置。任何人都知道它会是什么?这是苹果的错误吗?有解决方案吗?

谢谢!

编辑:添加了didUpdateLocations但整个问题是这个方法永远不会被调用

//Core Location Delegate Methods
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){

    //Set coordinates to global var
    let coordinates : CLLocationCoordinate2D = manager.location!.coordinate
    locValue = coordinates

    setCoordinatesDetails(coordinates)
    if(self.hasBeenLaunched == false){
        self.hasBeenLaunched = true
        loadCitySlugArray()
    }
}

0 个答案:

没有答案