简体   繁体   English

ios11 didUpdateLocations 未调用

[英]ios11 didUpdateLocations not called

I'm developing ios app using CLLocationManager.我正在使用 CLLocationManager 开发 ios 应用程序。

Until ios10, I called startUpdatingLocation, then didUpdateLocations is called, And I got a Location information.直到ios10,我调用startUpdatingLocation,然后调用didUpdateLocations,然后我得到了一个Location信息。

Now, I update iOS11 beta9 and Xcode beta6.现在,我更新了 iOS11 beta9 和 Xcode beta6。 I called startUpdatingLocation, but didUpdateLocations was not called.我调用了 startUpdatingLocation,但没有调用 didUpdateLocations。 So I cannot get any location.所以我找不到任何位置。

Location is core information on my app.位置是我的应用程序的核心信息。 Is there anyone who got same problem?有没有人遇到同样的问题? or can resolve this problem?或者可以解决这个问题? sorry for my poor english.对不起我糟糕的英语。 thank you.谢谢你。

In iOS 11 added new privacy key in info.plist, you should add any one of these, hope the addition in info.plist work for you. iOS 11 在 info.plist 中添加了新的隐私密钥,您应该添加其中任何一个,希望 info.plist 中的添加对您有用。

/*
*      Either the NSLocationAlwaysAndWhenInUseUsageDescription key or both the
*      NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription
*      keys must be specified in your Info.plist; otherwise, this method will do
*      nothing, as your app will be assumed not to support Always authorization.
*/

If you are running on simulator please make sure the simulator sets the location to custom location.如果您在模拟器上运行,请确保模拟器将位置设置为自定义位置。 By default it's select none.默认情况下选择无。 You can find it on simulator-> features -> locations It worked for me.您可以在模拟器-> 功能-> 位置上找到它对我有用。

Add in Info.plsit在 Info.plsit 中添加

privacy - location usage description
Privacy - Location When In Use Usage Description
Application NSLocationAlwaysUsageDescription

在此处输入图片说明

   func CheckLocationAuthorization()  {
    if CLLocationManager.locationServicesEnabled() {
        switch CLLocationManager.authorizationStatus() {
        case .notDetermined, .restricted, .denied:
            self.ShowLocationError()
        case .authorizedAlways, .authorizedWhenInUse:
            // Do stuff
        }
    } else {
        self.ShowLocationError()
    }
}

//MARK:Show location error
func ShowLocationError()   {
    _ = UIAlertController.showAlertInViewController(viewController: self, withTitle: kAlertTitle, message: "Please allow location for getting the current weather report", cancelButtonTitle: "Setting", destructiveButtonTitle: nil, otherButtonTitles: nil, tapBlock: { (a, b, c) in
        if let url = URL(string:UIApplication.openSettingsURLString) {
            UIApplication.shared.open(url)
        }
    })
}

I had a different issue.我有一个不同的问题。 I had accidentally declared the method as a class method instead of an instance method.我不小心将该方法声明为类方法而不是实例方法。

+ (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations

rather than而不是

- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations

Once I change the "+" to a "-", everything worked fine.一旦我将“+”更改为“-”,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM