Sunday 15 June 2014

ios - CLLocationManagerDelegate methods not being called in Swift code -



ios - CLLocationManagerDelegate methods not being called in Swift code -

i'm trying create simple app finds out part in, i'm stuck because none of cllocationmanagerdelegate methods called when app runs , finds locations.

in case it's relevant i'm not seeing dialog asking give app permission utilize location.

here's have far -

import uikit import corelocation class viewcontroller: uiviewcontroller, cllocationmanagerdelegate { @iboutlet weak var locationlabel : uilabel! var locationmanager = cllocationmanager() allow geocoder = clgeocoder () override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. locationmanager.delegate = self locationmanager.desiredaccuracy = kcllocationaccuracybest locationmanager.startupdatinglocation() } override func viewdiddisappear(animated: bool) { locationmanager.stopupdatinglocation() } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } func locationmanager(manager: cllocationmanager!, didupdatelocations locations: [anyobject]!) { geocoder.reversegeocodelocation(locations.last cllocation, completionhandler: {(placemark, error) in if (error != nil) { println("error") } else { allow pm = placemark.first clplacemark println(pm) } }) } func locationmanager(manager: cllocationmanager!, didfailwitherror error: nserror!) { println("epic fail") } }

i've set in breakpoints know code never called. have gone in , manually turned on location services app while it's been running too.

try calling

func locationmanager(manager: cllocationmanager!, didupdatetolocation newlocation: cllocation!, fromlocation oldlocation: cllocation!)

instead of delegate phone call making now... had problems with:

func locationmanager(manager: cllocationmanager!, didupdatelocations locations: [anyobject]!)

aswell. using above delegate phone call fixed issue.

edit (didn't read question properly...)

you never inquire permission, why don't popup. phone call following: locationmanager.requestwheninuseauthorization()

this quite of import step, , app won't work if haven't asked user authorization of app

it of import add together nslocationwheninuseusagedescription .plist file if running ios8.

screenshot:

ios swift core-location cllocationmanager

No comments:

Post a Comment