iOS Configuration API
Monitor offers three configuration options for iOS: Cloud (zero-config), JSON file, and Programmatic API. You can also combine them for a hybrid approach.
Token Setup
Before configuring protections, set up your ByteHide Project Token. You have three options:
Option A: Environment Variable (Recommended)
Configure BYTEHIDE_TOKEN in your Xcode scheme:
- Edit Scheme > Run > Arguments > Environment Variables
- Add:
BYTEHIDE_TOKEN=your-project-token
Option B: Info.plist
Add to your Info.plist:
<key>ByteHideMonitor</key>
<dict>
<key>APIToken</key>
<string>${BYTEHIDE_TOKEN}</string>
</dict><key>ByteHideMonitor</key>
<dict>
<key>APIToken</key>
<string>${BYTEHIDE_TOKEN}</string>
</dict>Then configure the BYTEHIDE_TOKEN environment variable (same as Option A).
Option C: JSON Configuration File
Include the token in a monitor-config.json file (see JSON Configuration below).
Configuration Options Overview
| Option | Best For | Code Required | Offline Support |
|---|---|---|---|
| Cloud (Zero-Config) | Most projects | None | No (fetches from API) |
| JSON File | Offline / auditable config | None | Yes |
| Programmatic API | Custom actions / dynamic logic | Yes | Yes |
Option A: Cloud Configuration (Zero-Config)
The simplest approach. Monitor fetches its configuration automatically from your ByteHide dashboard.
How it works:
- During build, the token is validated and configuration is embedded
- At runtime, Monitor auto-initializes using
+load()(beforemain()) - Applies protections configured in your dashboard
- Periodically syncs for configuration updates
Setup:
Configure your token (see above) and build:
xcodebuild -workspace YourApp.xcworkspace -scheme YourApp -configuration Releasexcodebuild -workspace YourApp.xcworkspace -scheme YourApp -configuration ReleaseNo code changes needed. Monitor initializes automatically.
Option B: JSON Configuration
Define protections locally in a JSON file. Ideal for offline environments or version-controlled configuration.
Create monitor-config.json in your project root:
{
"apiToken": "bh_YourToken",
"logLevel": "info",
"enableConsoleLogs": true,
"enableFileLogs": false,
"protections": [
{
"type": "DebuggerDetection",
"action": "close",
"intervalMs": 5000
},
{
"type": "JailbreakDetection",
"action": "close",
"intervalMs": 5000
},
{
"type": "SimulatorDetection",
"action": "log",
"intervalMs": 5000
},
{
"type": "ClockTampering",
"action": "log",
"intervalMs": 5000
},
{
"type": "MemoryDumpDetection",
"action": "close",
"intervalMs": 5000
},
{
"type": "ProcessInjection",
"action": "close",
"intervalMs": 5000
}
]
}{
"apiToken": "bh_YourToken",
"logLevel": "info",
"enableConsoleLogs": true,
"enableFileLogs": false,
"protections": [
{
"type": "DebuggerDetection",
"action": "close",
"intervalMs": 5000
},
{
"type": "JailbreakDetection",
"action": "close",
"intervalMs": 5000
},
{
"type": "SimulatorDetection",
"action": "log",
"intervalMs": 5000
},
{
"type": "ClockTampering",
"action": "log",
"intervalMs": 5000
},
{
"type": "MemoryDumpDetection",
"action": "close",
"intervalMs": 5000
},
{
"type": "ProcessInjection",
"action": "close",
"intervalMs": 5000
}
]
}Monitor loads this file automatically. No code required.
Option C: Programmatic Configuration
Configure Monitor directly in code for maximum control, custom actions, and dynamic logic.
Swift
import ByteHideMonitor
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplication.LaunchOptionsKey: Any]?) -> Bool {
BHMMonitor.configure { config in
// Token (optional if already embedded)
config.useToken("bh_YourToken")
// Set log level
config.logLevel(.info)
// Register a custom action
config.registerCustomAction("notify") { threat in
print("ALERT: \(threat.threatDescription ?? "Unknown threat")")
// Send notification, log to analytics, etc.
}
// Enable all protections with a default action
config.enableAllProtections(.log, intervalMs: 5000)
// Or configure individual protections
config.enableProtection(.debuggerDetection, action: .close, intervalMs: 5000)
config.enableProtection(.jailbreakDetection, customAction: "notify", intervalMs: 5000)
}
return true
}
}import ByteHideMonitor
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplication.LaunchOptionsKey: Any]?) -> Bool {
BHMMonitor.configure { config in
// Token (optional if already embedded)
config.useToken("bh_YourToken")
// Set log level
config.logLevel(.info)
// Register a custom action
config.registerCustomAction("notify") { threat in
print("ALERT: \(threat.threatDescription ?? "Unknown threat")")
// Send notification, log to analytics, etc.
}
// Enable all protections with a default action
config.enableAllProtections(.log, intervalMs: 5000)
// Or configure individual protections
config.enableProtection(.debuggerDetection, action: .close, intervalMs: 5000)
config.enableProtection(.jailbreakDetection, customAction: "notify", intervalMs: 5000)
}
return true
}
}Objective-C
#import <ByteHideMonitor/ByteHideMonitor.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[BHMMonitor configure:^(BHMMonitorConfiguration *config) {
// Token
[config useToken:@"bh_YourToken"];
// Set log level
[config logLevel:BHMLogLevelInfo];
// Register a custom action
[config registerCustomAction:@"notify" handler:^(BHMThreatContext *threat) {
NSLog(@"ALERT: %@", threat.threatDescription);
}];
// Enable all protections
[config enableAllProtections:BHMActionTypeLog intervalMs:5000];
// Or configure individual protections
[config enableProtection:BHMProtectionModuleTypeDebuggerDetection
action:BHMActionTypeClose
intervalMs:60000];
}];
return YES;
}
@end#import <ByteHideMonitor/ByteHideMonitor.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[BHMMonitor configure:^(BHMMonitorConfiguration *config) {
// Token
[config useToken:@"bh_YourToken"];
// Set log level
[config logLevel:BHMLogLevelInfo];
// Register a custom action
[config registerCustomAction:@"notify" handler:^(BHMThreatContext *threat) {
NSLog(@"ALERT: %@", threat.threatDescription);
}];
// Enable all protections
[config enableAllProtections:BHMActionTypeLog intervalMs:5000];
// Or configure individual protections
[config enableProtection:BHMProtectionModuleTypeDebuggerDetection
action:BHMActionTypeClose
intervalMs:60000];
}];
return YES;
}
@endAvailable Action Types
| Type | Description | Recommended Use |
|---|---|---|
| none | Detect only, take no action | Testing, initial analysis |
| log | Log the incident | Production monitoring |
| close | Close the application immediately | Maximum security |
| erase | Wipe sensitive data and close | Critical data (finance, health) |
| custom | Execute your custom handler | Business-specific logic |
Hybrid Configuration (Recommended for Production)
Combine cloud/JSON configuration with programmatic overrides:
BHMMonitor.configure { config in
// Base config is already loaded from cloud or monitor-config.json
// Override only what you need
config.registerCustomAction("criticalAlert") { threat in
sendPushNotification("Security Alert", threat.threatDescription ?? "Unknown threat")
exit(1)
}
// Add extra protection with custom action
config.enableProtection(.memoryDumpDetection, customAction: "criticalAlert", intervalMs: 60000)
}BHMMonitor.configure { config in
// Base config is already loaded from cloud or monitor-config.json
// Override only what you need
config.registerCustomAction("criticalAlert") { threat in
sendPushNotification("Security Alert", threat.threatDescription ?? "Unknown threat")
exit(1)
}
// Add extra protection with custom action
config.enableProtection(.memoryDumpDetection, customAction: "criticalAlert", intervalMs: 60000)
}Configuration loading order:
- Monitor loads from
monitor-config.json(if present in bundle) - If no JSON file, fetches configuration from cloud (dashboard)
- Applies programmatic configuration (if
Monitor.configureis called) - Programmatic configuration overrides automatic configuration
Auto-Initialization
Monitor for iOS auto-initializes automatically using the Objective-C +load() method, which executes before main().
How it works:
- During build: The token is validated and configuration is embedded in the app bundle
- During execution: Monitor initializes automatically before your code runs, validating the app signature and activating configured protections
No additional code is required unless you use Option C (programmatic configuration).