geolocation - iOS app only starting with huge delays after geo location event -
at moment adding geo fencing capabilities app. walked through tutorials , apple documentation find , still have huge issue. working, have issues when app or phone isn't actively being used.
in field tests went fine when had optimal conditions: phone charging , gps active (navigation software actively in use). app running in background , behaved want to.
but normal case not using phone actively when moving, not working expected. issues seems app isn't being woken enough ios able respond location events.
my logs revealed in 1 field test app not active 35 hours. in these 35 hours there several location events, should have had woken app respond them. instead of directly responding events app started (with uiapplicationlaunchoptionslocationkey) after 35 hours inactivity , responded location events ios detected in time frame. great ios detected these registered region transitions, why isn't starting app in reasonable time frame? doesn't have start directly when event occurs @ minimum within hour acceptable me.
can guys figure doing wrong?
in target's capabilities activated "background modes": location updates, background fetch , remote notifications.
below code.
this part initializing class dealing location events. geomanager class handling of that. @property (nonatomic) geomanager * geomanager; @implementation oneappdelegate
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { log(logleveldebug, @"-application:didfinishlaunchwithoptions: called; options: %@", launchoptions); ... self.geomanager = [geomanager sharedmanager]; return yes; } this bit of geomanager class:
class geomanager : nsobject { class var sharedmanager: geomanager { struct static { static let instance: geomanager = geomanager.init() } return static.instance } private var locationmanagerdelegate : locationmanagerdelegate? private let locationmanager = cllocationmanager() private override init() { super.init() guard uiapplication.shared.backgroundrefreshstatus == .available else { log(.info, "[geomanager] app isn't allowed background fetching.") return } locationmanagerdelegate = locationmanagerdelegate.init(geomanager: self) locationmanager.delegate = locationmanagerdelegate locationmanager.allowsbackgroundlocationupdates = true locationmanager.desiredaccuracy = kcllocationaccuracyhundredmeters; locationmanager.activitytype = .other log(.debug, "[geomanager] initiated") restorestoredfences() } } registering regions this:
let region = clcircularregion.init(center: cllocationcoordinate2d.init(latitude: lat, longitude: long), radius: radius, identifier: id) region.notifyonexit = transition == .exit region.notifyonentry = transition == .enter locationmanager.startmonitoring(for: region) this cllocationmanagerdelegate class:
class locationmanagerdelegate : nsobject, cllocationmanagerdelegate { private let geomanager : geomanager init(geomanager : geomanager) { self.geomanager = geomanager super.init() } func locationmanager(_ manager: cllocationmanager, didstartmonitoringfor region: clregion) { log(.info, "[geomanager] monitoring region id \(region.identifier) succeeded") } func locationmanager(_ manager: cllocationmanager, monitoringdidfailfor region: clregion?, witherror error: error) { if let region = region { log(.warning, "[geomanager] monitoring region id \(region.identifier) failed error \(error)") } else { log(.warning, "[geomanager] monitoring region failed error \(error)") } } func locationmanager(_ manager: cllocationmanager, didchangeauthorization status: clauthorizationstatus) { log(.info, "[geomanager] user changed location usage authorization \(status.rawvalue)") if status == .authorizedalways { log(.info, "[geomanager] configuring geo fences because user granted permissions use location") geomanager.configurefences(oneconnectioninfo.geodata()) } } func locationmanager(_ manager: cllocationmanager, didenterregion region: clregion) { if let transition = geomanager.transitions[region.identifier], transition == .enter { log(.info, "[geomanager] monitored region id \(region.identifier) entered") geomanager.triggerexecute(id: region.identifier) } } func locationmanager(_ manager: cllocationmanager, didexitregion region: clregion) { if let transition = geomanager.transitions[region.identifier], transition == .exit { log(.info, "[geomanager] monitored region id \(region.identifier) exited") geomanager.triggerexecute(id: region.identifier) } } func locationmanager(_ manager: cllocationmanager, didfailwitherror error: error) { log(.exception, "[geomanager] failed track locations error \(error)") } }
Comments
Post a Comment