Posts

Post not yet marked as solved
0 Replies
83 Views
I am writing an application that will, on the high end, have a screen-on time of > 1 hour. While the app is in use, it will need to send a heartbeat to a server via an open socket every so many seconds (usually a value between 4s and 29s), as shown below. connection = NWConnection(host: .init(combinedAddress), port: .init(integerLiteral: port), using: .tcp) if let ipOptions = connection.parameters.defaultProtocolStack.internetProtocol as? NWProtocolIP.Options { ipOptions.version = .v4 } connection.parameters.preferNoProxies = true DispatchQueue.global(qos: .default).async { self.heartbeatTimer = Timer.scheduledTimer(withTimeInterval: self.getHeartbeatInterval(), repeats: true, block: { _ in self.sendHeartbeat() // eventually connection.send("heartbeat data... ", completion: {...} ) }) RunLoop.current.run() } During periods of less user interaction, the only data going across the network will be the heartbeat. According to this page, there's a periods of high power network activity, followed by another less energy intensive period, before the energy draw drops back down to baseline levels. I have slight control over the heartbeat interval, and if X seconds keeps the radio at full power and Y seconds can give my users a Y-X second period of lower energy state, I can increase the time between heartbeats and take advantage of the lower power state to prevent the battery from getting hammered. Is there a document that will provide times for the values shown in the graph, or otherwise provide guidance on how long network requests can/should be delayed for an optimized battery life? Thank you in advance. Note: This should all happen via Wifi, and for various reasons there's no need to take cellular modems into account.
Posted
by hoffmand5.
Last updated
.