ios - CLError.DeferredFailed Error (kCLErrorDomain Code=11) Deferred GPS Updates Failing -
i have app periodic location updates map users path.
i using deferred updates.
if (cllocationmanager.deferredlocationupdatesavailable() == true && _isdeferingupdates == false) { print("doing refresh") _isdeferingupdates = true _locationmanager.allowdeferredlocationupdatesuntiltraveled(c_gps.activity_update_distance, timeout: c_gps.activity_update_time) } else { print("could not refresh") // iphone 4s not have deferring must keep on _locationmanager.startupdatinglocation() }
when app open "doing refresh" call every second.
my setup:
have 2 keys on plist nslocationwheninuseusagedescription && nslocationalwaysusagedescription
have background modes turned on, remote notifcations , location updates.
have maps setup use bike , pedestrian.
have permissions on phone set yes.
do know other reason why deferred update failing when app goes background?
its never working , apples documentation less helpful
deferredfailed location manager did not enter deferred mode unknown reason. error can occur if gps unavailable, not active, or temporarily interrupted. if error on device has gps hardware, solution try again.
here error handler:
func locationmanager(manager: cllocationmanager, didfinishdeferredupdateswitherror error: nserror?) { print("finished background update error \(error)") if (error != nil) { print("error valid clerror") if (error!.code == clerror.locationunknown.rawvalue) { print("error: location unknown") } else if (error!.code == clerror.deferredaccuracytoolow.rawvalue) { print("error: accuracy low") } else if (error!.code == clerror.deferredfailed.rawvalue) { print("error: deferring failed") } else if (error!.code == clerror.denied.rawvalue) { print("error: denied") } else { print("error not handled") } } _isdeferingupdates = false }
ios 9.2, xcode 7.2, arc enabled
the problem associated distance , time interval have chosen deferral. try take advantage of cllocationdistancemax
and cltimeintervalmax
troubleshoot function call. example, set distance cllocationdistancemax
, vary time interval, try vice versa.
but there other things see might want change...
- get rid of
cllocationmanager.deferredlocationupdatesavailable() == true
condition in if statements allow deferred location updates. - deferred updates available ios6.0+, iphone 4s can updated ios7.2.1 depending on hardware. not need separately call
_locationmanager.startupdatinglocation()
. - make sure if testing in ios9.0+ have
allowsbackgroundlocationupdates
set location manager. - make sure initial
_locationmanager.startupdatinglocation()
made in- (void)applicationwillresignactive:(uiapplication *)application
method equivalent in swift , not in- (void)applicationdidenterbackground:(uiapplication *)application
method. - make sure calling
_locationmanager.allowdeferredlocationupdatesuntiltraveled(c_gps.activity_update_distance, timeout: c_gps.activity_update_time)
in equivalent of- (void)locationmanager:(cllocationmanager *)manager didupdatelocations:(nsarray<cllocation *> *)locations
method swift.
also, note printing error before check if error exists, might lead incorrect error reporting.
hope helps , not late! cheers.
p.s. if doesn't work, please post more of code, i.e. calling these functions in relation app. delegate *.m file.
Comments
Post a Comment