SpeedOf.Me API - macOS Integration

This example demonstrates how to integrate the SpeedOf.Me speed test API into a macOS app using WKWebView.

How It Works

The SpeedOf.Me API is JavaScript-based, so macOS apps use WKWebView to:

  1. Load an HTML page containing the speed test
  2. Receive results via WKScriptMessageHandler

This is very similar to the iOS example, with macOS-specific UI adaptations.

Files

Prerequisites

Key Differences from iOS

AspectiOSmacOS
View wrapperUIViewRepresentableNSViewRepresentable
Make viewmakeUIViewmakeNSView
Update viewupdateUIViewupdateNSView
Window styleN/A.windowStyle(.titleBar)

Quick Start

1. Create a New macOS App

In Xcode: File > New > Project > macOS > App (SwiftUI)

2. Add Files

Copy speedtest.html and SpeedTestView.swift to your project.

3. Configure API Credentials

SomApi.account = "YOUR_API_KEY";
SomApi.domainName = "your-domain.com";

App Sandbox Entitlements

For network access, add to your .entitlements file:

<key>com.apple.security.network.client</key>
<true/>

Window Configuration

WindowGroup {
    SpeedTestView()
        .frame(minWidth: 400, idealWidth: 450, minHeight: 500, idealHeight: 600)
}
.windowStyle(.titleBar)
.windowResizability(.contentMinSize)

Menu Bar App (Alternative)

@main
struct SpeedTestApp: App {
    var body: some Scene {
        MenuBarExtra("Speed Test", systemImage: "speedometer") {
            SpeedTestView()
                .frame(width: 350, height: 450)
        }
        .menuBarExtraStyle(.window)
    }
}

Distribution

Mac App Store

  1. Archive your app in Xcode
  2. Upload to App Store Connect
  3. Requires Apple Developer account

Direct Distribution

  1. Archive in Xcode
  2. Export as "Developer ID" signed app
  3. Notarize with Apple
  4. Distribute via your website

Troubleshooting

Links