Require Internet Connection with the .requireNetwork() View Modifier
Need to make sure that the app is connected to the internet to avoid showing content that is not available offline?
The .requireNetwork()
view modifier allows you to require the phone to be connected to the internet to show a specific view, otherwise the view will be hidden.
View Modifier declaration:
requireNetwork.swift
extension View {
public func requireNetwork() -> some View {
modifier(RequireInternet())
}
}
Simply apply it to the view you want to hide:
import SharedKit
import SwiftUI
struct SuperSecretView: View {
var body: some View {
VStack {
Text("Congrats, you have Internet Access!")
}
.requireNetwork()
}
}