How to get Location user with CLLocationManager in swift?

前端 未结 7 2089
鱼传尺愫
鱼传尺愫 2020-11-29 04:49

I have this code on my view controller but this not working:

  import UIKit
  import CoreLocation

  class ViewController: UIViewController, CLLocationManag         


        
7条回答
  •  孤城傲影
    2020-11-29 05:24

    Since you're declaring location as an explicitly unwrapped optional (CLLocationManager!) it requires an initializer, either in an init method as suggested by jhurray, or just inline, as:

    var location: CLLocationManager! = nil
    

    Note that you've got other possible problems as well, including that iOS 8 has new requirements for querying the user for permission to use CoreLocation. See this question for more information.

提交回复
热议问题