For the captive-portal detection part, there’s an RFC covering it: The network provider can tell the device where to send the user, and can provide an endpoint to get info like how long is left on the session.
Apple has a page on it, here: https://developer.apple.com/news/?id=q78sq5rv