相关疑难解决方法(0)

CLLocationManager.authorizationStatus()始终使用swift&objC app确认CLAuthorizationStatus.NotDetermined

我只能让我的CLLocationManager进行授权.(在ios8下迅速)我甚至添加了一个显式的requestAlwaysAuthorization调用(在ios7下我不需要使用objC)

func finishLaunch() {
    //ask for authorization
    let status = CLLocationManager.authorizationStatus()
    if(status == CLAuthorizationStatus.NotDetermined) {
        self.locationManager.requestAlwaysAuthorization();
    }
    else {
        self.startMonitoring()
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

回调永远不会得到任何东西,但NotDermined并没有向用户显示UIAlertView.

func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
    if(status == CLAuthorizationStatus.NotDetermined) {
        println("Auth status unkown still!");
    }
    self.startMonitoring()
}
Run Code Online (Sandbox Code Playgroud)

我做错了吗? - 对我来说感觉像个臭虫,但我想要一些反馈

cllocationmanager swift ios8

21
推荐指数
1
解决办法
3万
查看次数

iOS应用不会要求位置许可

我的Swift-iOS应用程序旨在显示用户在地图上的位置.但是,XCode调试控制台告诉我,我需要请求权限才能显示用户的位置.我想,我这样做,但对话永远不会出现.

这是错误消息,在我调用的ViewController下面 CLLocationManager::requestWhenInUseAuthorization()

错误:

2014-06-30 21:25:13.927 RowingTracker2 [17642:1608253]尝试在不提示位置授权的情况下启动MapKit位置更新.必须首先调用 - [CLLocationManager requestWhenInUseAuthorization]或 - [CLLocationManager requestAlwaysAuthorization].

视图控制器:

import UIKit
import MapKit
import CoreLocation

class ViewController: UIViewController, MKMapViewDelegate {
    @IBOutlet var mapview: MKMapView = nil
    var locationmgr : CLLocationManager!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        locationmgr = CLLocationManager()
        locationmgr.requestWhenInUseAuthorization()
        mapview.showsUserLocation = true
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
Run Code Online (Sandbox Code Playgroud)

如何申请授权使用该位置?你可以在这里 …

core-location mapkit ios swift

9
推荐指数
2
解决办法
2万
查看次数

LocationServicesEnabled:不推荐使用API

我使用这里的代码:

import UIKit 
import CoreLocation

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {

var window: UIWindow?
var locationManager: CLLocationManager!
var seenError : Bool = false
var locationFixAchieved : Bool = false
var locationStatus : NSString = "Not Started"

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
    initLocationManager();
    return true
}

// Location Manager helper stuff
func initLocationManager() {
    seenError = false
    locationFixAchieved = false
    locationManager = CLLocationManager()
    locationManager.delegate = self
    locationManager.locationServicesEnabled
    locationManager.desiredAccuracy = kCLLocationAccuracyBest

    locationManager.requestAlwaysAuthorization()
}

// Location …
Run Code Online (Sandbox Code Playgroud)

ios swift

6
推荐指数
1
解决办法
3624
查看次数

Swift 2 - 无法通过CLLocationManager获取用户位置

这是我的VC代码:

import UIKit
import MapKit
import CoreLocation

class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
    @IBOutlet weak var mapView: MKMapView!
    let locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()

        locationManager.delegate = self
        locationManager.requestWhenInUseAuthorization()
        mapView.showsUserLocation = true
    }

    func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
        mapView.showsUserLocation = (status == .AuthorizedAlways)
    }

    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let locValue:CLLocationCoordinate2D = manager.location!.coordinate
        print("locations = \(locValue.latitude) \(locValue.longitude)")
    }
}
Run Code Online (Sandbox Code Playgroud)

我还在plist文件中添加了NSLocationWhenInUseUsageDescription.我有CoreLocation和MapKit框架,任何想法为什么这不起作用?它不会在地图上显示用户位置,也不会打印出用户的坐标.在堆栈溢出时没有在网上找到任何东西.

cllocationmanager ios swift xcode7 swift2

3
推荐指数
1
解决办法
4657
查看次数

标签 统计

swift ×4

ios ×3

cllocationmanager ×2

core-location ×1

ios8 ×1

mapkit ×1

swift2 ×1

xcode7 ×1