EMP EMP - 1 month ago 19
iOS Question

xcode 8 swift 3 latlong working on simulator but not in device

I have this code to get location latlong

import Foundation
import CoreLocation

class Utilities{

static let locationManager = CLLocationManager()

static func InitLocator(Delegate:CLLocationManagerDelegate){

locationManager.desiredAccuracy = kCLLocationAccuracyBest

locationManager.delegate = Delegate

locationManager.requestAlwaysAuthorization()

locationManager.distanceFilter = kCLDistanceFilterNone

locationManager.startUpdatingLocation()


}

static func GetLatLong() -> [String]{


var arrLatLong:[String] = []

if let latitude = locationManager.location?.coordinate.latitude{
arrLatLong.append(String(latitude))
}else{
arrLatLong.append("")
}

if let longitude = locationManager.location?.coordinate.longitude{
arrLatLong.append(String(longitude))
}else{
arrLatLong.append("")
}

return arrLatLong

}

}


This works when I test or run it in the simulator but when I test it in an actual device it gives me blank values. I use Xcode 8 swift, the device is Iphone 6s IOS 9.3.1

Answer

Try with

adding locationManager.requestWhenInUseAuthorization() and info.plist

Comments