swift - CLLocationManagerDelegate not receiving updates -
i have view controller hase these functions:
func locationmanager(manager: cllocationmanager, didupdatelocations locations: [cllocation]){ print("loc") } func locationmanager(manager: cllocationmanager, didfailwitherror error: nserror){ if(error.code == clerror.denied.rawvalue){ print("error") } } it direct child of class:
import uikit import corelocation class uiviewlocationmanager : uiviewcontroller, cllocationmanagerdelegate{ func locationmanager(manager: cllocationmanager, didchangeauthorizationstatus status: clauthorizationstatus) { print(status.rawvalue) switch status { case .notdetermined: break case .authorizedwheninuse: if #available(ios 9.0, *) { manager.requestlocation() } else { manager.startupdatinglocation() } break case .authorizedalways: break case .denied: break default: break } } } and have class
class corelocationcontroller : nsobject { func requestlocationupdate(delegate : cllocationmanagerdelegate){ let locationmanager = cllocationmanager() locationmanager.delegate = delegate if #available(ios 8.0, *) { locationmanager.requestwheninuseauthorization() } else { locationmanager.startupdatinglocation() } then in appdelegate declare like:
let corelocationcontroller = corelocationcontroller() but when call requestlocationupdate(self) viewcontroller child of uiviewlocationmanager dont receive updates. if copy-paste methods corelocationcontroller , locationmanager.delegate = self in corelocationcontroller init() method works fine.
any ideas? desperate because have tried aproaches still cant working.
thanks in forward
locationmanager local variable within requestlocationupdate method. @ end of call requestlocationupdate, locationmanager destroyed , cllocationmanager created have nothing referencing it, destroyed too, despite fact have asked send messages extant delegate.
if instance of corelocationcontroller have created not destroyed - points instance - changing locationmanager instance variable should fix this:
class corelocationcontroller : nsobject { var locationmanager:cllocationmanager? func requestlocationupdate(delegate : cllocationmanagerdelegate) { locationmanager = cllocationmanager() locationmanager?.delegate = delegate locationmanager?.requestwheninuseauthorization() } } the above code working me in real iphone 5 , in simulated iphone 6. location update delegate code gets called. did have edit plist specified in cllocation manager in swift location of user
Comments
Post a Comment