Initialization
Initialize Early
Initialize the SDK at app launch, not when first needed. The correct order is: initialize → register backends → register models.Pre-load Models
Load models during onboarding or splash screen:Memory Management
Unload When Not Needed
Free memory by unloading unused models:Monitor Memory
Handle Memory Warnings
Model Selection
Choose Appropriate Model Sizes
| Device | Recommended LLM | Notes |
|---|---|---|
| iPhone 12/13 (4GB) | 1B Q4 | May need to unload others |
| iPhone 14/15 (6GB) | 1-3B Q4 | Good for most use cases |
| iPhone 15 Pro (8GB) | 3B Q4, some 7B | More headroom |
| iPad Pro | 3-7B Q4 | Depends on RAM |
| M1+ Mac | 7B+ Q4 | Ample memory |
Device-Specific Loading
Streaming for Responsiveness
Always Stream for Long Outputs
Batch UI Updates
Threading
Use Appropriate Actors
Don’t Block the Main Thread
Error Recovery
Implement Retries
Graceful Fallbacks
Storage
Check Before Downloads
Clean Up Regularly
Event Handling
Subscribe to Events
Testing
Use Development Environment
Mock for Unit Tests
Platform Gotchas
Permissions (Info.plist)
Your app’sInfo.plist must include usage descriptions for all hardware your app accesses:
| Key | Required For | Example Value |
|---|---|---|
NSMicrophoneUsageDescription | STT, Voice Pipeline | ”This app uses the microphone for on-device speech recognition.” |
NSSpeechRecognitionUsageDescription | STT | ”This app uses on-device speech recognition.” |
NSCameraUsageDescription | VLM (Vision) | “This app uses the camera for on-device vision AI.” |
NSPhotoLibraryUsageDescription | VLM, Diffusion | ”This app accesses your photo library for on-device image analysis.” |
macOS App Sandbox
For macOS targets, disable the App Sandbox to allow model file downloads and storage: SetENABLE_APP_SANDBOX = NO in your Xcode build settings.
Backend Registration Order
Backends must be registered afterRunAnywhere.initialize() and before any model registration or loading:
Sequential Model Downloads
Download models sequentially (not in parallel) to avoid race conditions in the SDK’s download service:VLM Model Loading
VLM model loading requires aModelDescriptor object, not just a model ID. Fetch it from availableModels():
Try-Then-Download Pattern
Always attemptloadModel() first (succeeds if the model is already cached), and only download on failure:
Audio Format for STT
STT transcription requires audio recorded as 16kHz, mono, 16-bit linear PCM (WAV). The minimum data threshold is ~1600 bytes (~0.1 seconds at 16kHz).Platform-Conditional Code (iOS vs macOS)
When building for both iOS and macOS, use conditional compilation for platform-specific APIs:AVAudioSession is only available on iOS — skip audio session setup on macOS.
Quick Reference
| Scenario | Recommendation |
|---|---|
| App launch | Initialize SDK, register modules |
| Before first use | Pre-load models |
| Long text generation | Use streaming |
| Low memory devices | Use smaller models, unload when done |
| Voice features | Use Voice Agent for full pipeline |
| Production | Set log level to .warning |
| Errors | Implement retries and fallbacks |
| Background | Unload models to free memory |