This example demonstrates how to integrate the SpeedOf.Me speed test API into a macOS app using WKWebView.
The SpeedOf.Me API is JavaScript-based, so macOS apps use WKWebView to:
This is very similar to the iOS example, with macOS-specific UI adaptations.
| Aspect | iOS | macOS |
|---|---|---|
| View wrapper | UIViewRepresentable | NSViewRepresentable |
| Make view | makeUIView | makeNSView |
| Update view | updateUIView | updateNSView |
| Window style | N/A | .windowStyle(.titleBar) |
In Xcode: File > New > Project > macOS > App (SwiftUI)
Copy speedtest.html and SpeedTestView.swift to your project.
SomApi.account = "YOUR_API_KEY";
SomApi.domainName = "your-domain.com";
For network access, add to your .entitlements file:
<key>com.apple.security.network.client</key>
<true/>
WindowGroup {
SpeedTestView()
.frame(minWidth: 400, idealWidth: 450, minHeight: 500, idealHeight: 600)
}
.windowStyle(.titleBar)
.windowResizability(.contentMinSize)
@main
struct SpeedTestApp: App {
var body: some Scene {
MenuBarExtra("Speed Test", systemImage: "speedometer") {
SpeedTestView()
.frame(width: 350, height: 450)
}
.menuBarExtraStyle(.window)
}
}
com.apple.security.network.client entitlementminWidth/minHeight in frame modifier