我使用 here得代碼:
import UIKit import CoreLocation@UIApplicationMainclass AppDelegate: UIResponder,UIApplicationDelegate,CLLocationManagerDelegate {var window: UIWindow?var locationManager: CLLocationManager!var seenError : Bool = falsevar locationFixAchieved : Bool = falsevar locationStatus : NSString = "Not Started"func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool { initLocationManager(); return true}// Location Manager helper stufffunc initLocationManager() { seenError = false locationFixAchieved = false locationManager = CLLocationManager() locationManager.delegate = self locationManager.locationServicesEnabled locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.requestAlwaysAuthorization()}// Location Manager Delegate stufffunc locationManager(manager: CLLocationManager!,didFailWithError error: NSError!) { locationManager.stopUpdatingLocation() if (error) { if (seenError == false) { seenError = true print(error) } }}func locationManager(manager: CLLocationManager!,didUpdateLocations locations: AnyObject[]!) { if (locationFixAchieved == false) { locationFixAchieved = true var locationArray = locations as NSArray var locationObj = locationArray.lastObject as CLLocation var coord = locationObj.coordinate println(coord.latitude) println(coord.longitude) }}func locationManager(manager: CLLocationManager!,didChangeAuthorizationStatus status: CLAuthorizationStatus) { var shouldIAllow = false switch status { case CLAuthorizationStatus.Restricted: locationStatus = "Restricted Access to location" case CLAuthorizationStatus.Denied: locationStatus = "User denied access to location" case CLAuthorizationStatus.NotDetermined: locationStatus = "Status not determined" default: locationStatus = "Allowed to location Access" shouldIAllow = true } NSNotificationCenter.defaultCenter().postNotificationName("LabelHasbeenUpdated",object: nil) if (shouldIAllow == true) { NSLog("Location to Allowed") // Start location services locationManager.startUpdatingLocation() } else { NSLog("Denied access: (locationStatus)") }}}
但是我有一個錯誤:
‘locationServicesEnabled’不可用:在iOS 7及更早版本中棄用得API在Swift中不可用.
任何人都知道,如何解決這個問題?
謝謝!
解決方法
自iOS 4.0起CLLocationManager is deprecated實例上得locationServicesEnabled屬性,但 class method不是.
所以代替:
locationManager.locationServicesEnabled
您應該只使用以下代碼:
CLLocationManager.locationServicesEnabled()
以上是來客網為你收集整理得ios – LocationServicesEnabled:不推薦使用API全部內容,希望內容能夠幫你解決ios – LocationServicesEnabled:不推薦使用API所遇到得程序開發問題。
如果覺得來客網網站內容還不錯,歡迎將來客網網站推薦給程序員好友。
聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。