iOS SDK
This guide adds runtime protection to an iOS app. You need macOS and Xcode to build and test it.
1. Add the Swift Package
In Xcode: File -> Add Package Dependencies, then the URL:
https://github.com/moatgator-hq/sdk-ios.git
Or in Package.swift:
.package(url: "https://github.com/moatgator-hq/sdk-ios.git", from: "0.1.0")
The minimum deployment target is iOS 13.
2. Start the SDK
Start it once, as early as possible:
import Moatgator
@main
struct MyApp: App {
init() {
Moatgator.start(MoatgatorConfig(
apiKey: BuildSecrets.moatgatorKey, // console -> app -> Keys (scope: events:ingest)
pins: ["sha256/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="],
expectedBundleId: "com.acme.pay"
))
}
var body: some Scene { WindowGroup { ContentView() } }
}
React to a threat — the decision is yours:
final class Guard: ThreatListener {
func onThreat(_ f: Finding) {
if f.threat == .jailbreak || f.threat == .hooking { PaymentGate.block() }
}
}
Moatgator.shared.addListener(Guard())
3. Pin your server's public key (optional, recommended)
Certificate pinning adds a check on top of the system's TLS validation, so a man-in-the-middle with a different certificate is refused. Pin the public key (SPKI), not the certificate, so renewing the certificate with the same key keeps working:
# from the server's leaf certificate
openssl s_client -connect api.moatgator.com:443 </dev/null 2>/dev/null \
| openssl x509 -pubkey -noout \
| openssl pkey -pubin -outform der \
| openssl dgst -sha256 -binary | openssl base64
List two pins (current plus the next rotation) so a key change never locks the app out.
4. Run the tests
The detectors use an injectable probe, so the unit tests run without an iPhone:
swift test
They cover a stock device (nothing fires), jailbreak, hooking, debugger and tampering with the right signals, and the event.v1 format.
5. Test on a device
Build to a real iPhone (or TestFlight). On a stock device the SDK should report nothing; on a jailbroken device, or with Frida attached, it reports jailbreak/hooking with high confidence. Watch the console under Threats.
Notes
- The SDK never crashes your app. Every check is wrapped and tolerant of failure.
- App Store safe. The SDK uses public APIs, or resolves non-public symbols (
ptrace,fork) at runtime, so it does not risk review. - No personal data. The device becomes a rotating hash; no special permission is required.