Setup:Probleme bekommen device/Benutzerort mit IOS App, Swift
- Xcode 7,3 (7D175)
- Swift 2
- Gerät ist ein iPad mit IOS 9.3.1
Ich habe eine Swift-Klasse namens LocationUtility
, ich benutze es so in einem ViewController:
let locationUtil = LocationUtility()
locationUtil.initLocationManager()
Die initLocationManager()
Funktion setzt die CLLocationManager.delegate
meine LocationUtility
Klasse:
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
Ich habe NSLocationAlwaysUsageDescription
string in meinem Info.plist
gesetzt:
func initLocationManager() {
seenError = false
locationFixAchieved = false
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
if CLLocationManager.locationServicesEnabled() {
locationManager.startUpdatingLocation()
}
}
Die folgend Delegierten func aufgerufen wird nie werden Auf meinem iPad ist Datenschutz -> Standortdienste aktiviert.
Meine LocationUtility-Klasse ist etwas, zusammen mit Code aus anderen stackoverflow Fragen und Antworten über Standortfunktionen in Swift und iOS 8 und darüber hinaus. Aus meiner Sicht habe ich alle richtigen Einstellungen in meiner App und auf meinem Gerät, um Standortinformationen zu erhalten.
Hier ist meine komplette LocationUtility
Klasse Quellcode:
import UIKit
import Foundation
import CoreLocation
class LocationUtility: UIViewController, CLLocationManagerDelegate {
var locationStatus : NSString = "Not Started"
var locationManager: CLLocationManager!
var seenError : Bool = false
var locationFixAchieved : Bool = false
var currentLocation:CLLocation? = nil
func initLocationManager() {
seenError = false
locationFixAchieved = false
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
if CLLocationManager.locationServicesEnabled() {
//locationManager.delegate = self
//locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.startUpdatingLocation()
}
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print("LocationUtility -> didFailWithError()")
locationManager.stopUpdatingLocation()
if (seenError == false) {
seenError = true
print(error)
}
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print("LocationUtility -> didUpdateLocations()")
if (locationFixAchieved == false) {
locationFixAchieved = true
//var locationArray = locations as NSArray
currentLocation = locations.last! as CLLocation
let coord = currentLocation!.coordinate
print("user current location")
print(coord.latitude)
print(coord.longitude)
}
}
// authorization status
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
print("LocationUtility -> didChangeAuthorizationStatus()!")
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
}
if (shouldIAllow == true) {
NSLog("Location to Allowed")
// Start location services
locationManager.startUpdatingLocation()
} else {
NSLog("Denied access: \(locationStatus)")
}
}
}
Nein, es geht nicht. – Roee84
Danke @ Roee84 Ich habe meine Frage "title" geändert und meine Frage dann bearbeitet, damit ich über meine Delegiertenfrage hinaus weiterhelfen konnte, danke für Ihr Feedback. –
Wird die Methode 'didChangeAuthorizationStatus' jemals aufgerufen? Wenn ja, mit welchem Wert für "Status"? –