EMP EMP - 1 year ago 115
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.distanceFilter = kCLDistanceFilterNone



static func GetLatLong() -> [String]{

var arrLatLong:[String] = []

if let latitude = locationManager.location?.coordinate.latitude{

if let longitude = locationManager.location?.coordinate.longitude{

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 Source

Try with

adding locationManager.requestWhenInUseAuthorization() and info.plist

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download