of scope relative to your listener let reachability = Reachability()! reachability.whenReachable = { reachability in if reachability.connection == .wifi { print("Reachable via WiFi") } else { print("Reachable via Cellular") } } reachability.whenUnreachable = { _ in print("Not reachable") } do { try reachability.startNotifier() } catch { print("Unable to start notifier") }
to guess whether network service is available, and do not cache that determination.” https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/NetworkingOverview/WhyNetworkingIsHard/WhyNetworkingIsHard.html#//apple_ref/doc/ uid/TP40010220-CH13-SW3 ଓΛࢼΈΔલʹνΣοΫΛ͍͚ͯ͠ͳ͍
as a preflight mechanism for determining network connectivity. You determine network connectivity by attempting to connect. If the connection fails consult the SCNetworkReachability API to help diagnose the cause of the failure. https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/NetworkingOverview/WhyNetworkingIsHard/WhyNetworkingIsHard.html#//apple_ref/doc/ uid/TP40010220-CH13-SW3 ·ͣଓΛࢼͯ͠Έͯ ࣦഊͨ͠ͱ͖ͷݪҼΛಛఆ͢ΔͨΊʹ͏
nil) 63-4FTTJPOEFMFHBUFΛڧࢀর͢Δ “The session object keeps a strong reference to the delegate until your app exits or explicitly invalidates the session. If you don’t invalidate the session, your app leaks memory until it exits.” session.invalidateAndCancel()