The Salesforce Mobile SDK for iOS Hybrid provides the iOS native bridge layer for Cordova-based hybrid applications. It bridges JavaScript Cordova plugins to the iOS native Mobile SDK libraries, enabling hybrid apps to leverage full native SDK functionality.
Key constraint: This is a public SDK. Every change is visible to external developers. Backward compatibility, deprecation cycles, and semver discipline are non-negotiable.
Hybrid App (HTML/JS/Cordova)
βββ Cordova Plugins (from Shared repo)
βββ SalesforceHybridSDK (this repo)
βββ Cordova Plugin Bridges (Objective-C)
β βββ SalesforceOAuthPlugin
β βββ SFSmartStorePlugin
β βββ SFMobileSyncPlugin
β βββ SFNetworkPlugin
β βββ SFSDKInfoPlugin
β
βββ Hybrid View Management
β βββ SFHybridViewController
β βββ SFHybridViewConfig
β βββ SalesforceWebViewCookieManager
β
βββ iOS Native SDK (dependencies)
βββ MobileSync
βββ SmartStore
βββ SalesforceSDKCore
βββ SalesforceAnalytics
βββ SalesforceSDKCommon
Workspace: SalesforceMobileSDK-Hybrid.xcworkspace
SalesforceMobileSDK-iOS-Hybrid/
βββ libs/
β βββ SalesforceHybridSDK/ # Main hybrid bridge library
β β βββ SalesforceHybridSDK/ # Library code
β β β βββ Classes/
β β β β βββ Plugins/ # Cordova plugin implementations
β β β β βββ SFHybridViewController.{h,m}
β β β β βββ SFHybridViewConfig.{h,m}
β β β β βββ SalesforceWebViewCookieManager.swift
β β β β βββ SalesforceHybridSDKManager.{h,m}
β β β βββ SalesforceHybridSDK.h
β β βββ SalesforceHybridSDKTests/ # Unit tests
β β βββ SalesforceHybridSDK.xcodeproj
β β
β βββ SalesforceFileLogger/ # File-based logging library
β βββ SalesforceFileLogger/ # Library code
β βββ SalesforceFileLoggerTests/ # Unit tests
β βββ SalesforceFileLogger.xcodeproj
β
βββ hybrid/SampleApps/ # Sample applications
β βββ AccountEditor/ # Account CRUD sample
β βββ MobileSyncExplorerHybrid/ # MobileSync demo app
β
βββ external/ # Git submodules
β βββ SalesforceMobileSDK-iOS/ # iOS native SDK (submodule)
β βββ shared/ # SalesforceMobileSDK-Shared (submodule)
β βββ cordova/ # Apache Cordova iOS (submodule)
β βββ CocoaLumberjack/ # Logging library (submodule)
β
βββ shared/ # Shared resources
β βββ hybrid/ # Hybrid-specific code
β β βββ AppDelegate.m # App delegate template
β β βββ InitialViewController.{h,m}
β β βββ UIApplication+SalesforceHybridSDK.{h,m}
β βββ common/ # Common utilities
β
βββ SalesforceMobileSDK-Hybrid.xcworkspace
βββ install.sh # Setup script
Purpose: Bridge Cordova JavaScript plugins to iOS native SDK
Key Components:
| Component | Purpose |
|---|---|
| SFHybridViewController | Main view controller for Cordova WebView, authentication flow, lifecycle management |
| SFHybridViewConfig | Configuration for hybrid views (local/remote, authentication settings) |
| SalesforceWebViewCookieManager | WKWebView cookie management for Salesforce sessions |
| SalesforceHybridSDKManager | Singleton SDK manager, hybrid-specific configuration |
| SFHybridConnectionMonitor | Network connectivity monitoring |
| SFLocalhostSubstitutionCache | Local file serving optimization |
Cordova Plugins (in Classes/Plugins/):
| Plugin | Native Class | Purpose |
|---|---|---|
| OAuth | SalesforceOAuthPlugin |
Authentication, user management, logout |
| SmartStore | SFSmartStorePlugin |
Encrypted local storage operations |
| MobileSync | SFMobileSyncPlugin |
Data synchronization framework |
| Network | SFNetworkPlugin |
REST API requests to Salesforce |
| SDKInfo | SFSDKInfoPlugin |
SDK version and configuration info |
| Account Manager | SFAccountManagerPlugin |
Multi-user account management |
Purpose: File-based logging for hybrid apps
Features:
- Log rotation and management
- Configurable log levels
- Log file export for debugging
- Integration with CocoaLumberjack
Declared in podspecs and pulled from iOS SDK:
pod 'MobileSync'
pod 'SmartStore'
pod 'SalesforceSDKCore'
pod 'SalesforceAnalytics'
pod 'SalesforceSDKCommon'
pod 'Cordova' # Apache Cordova for iOS
pod 'CocoaLumberjack' # Logging frameworkexternal/SalesforceMobileSDK-iOS # iOS native SDK
external/shared # Shared JavaScript libraries
external/cordova # Apache Cordova iOS
external/CocoaLumberjack # Logging library- macOS: Required for iOS development
- Xcode: 15+ recommended
- iOS: Minimum deployment target 18.0
- CocoaPods: For dependency management
# Clone the repository
git clone https://github.com/forcedotcom/SalesforceMobileSDK-iOS-Hybrid.git
cd SalesforceMobileSDK-iOS-Hybrid
# Run install script to pull submodules
./install.sh
# Open the workspace
open SalesforceMobileSDK-Hybrid.xcworkspaceImportant: Always open .xcworkspace, not .xcodeproj files.
# Build SalesforceHybridSDK
xcodebuild -workspace SalesforceMobileSDK-Hybrid.xcworkspace \
-scheme SalesforceHybridSDK \
-sdk iphonesimulator \
build
# Run tests for SalesforceHybridSDK
xcodebuild test -workspace SalesforceMobileSDK-Hybrid.xcworkspace \
-scheme SalesforceHybridSDK \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 15'
# Build SalesforceFileLogger
xcodebuild -workspace SalesforceMobileSDK-Hybrid.xcworkspace \
-scheme SalesforceFileLogger \
-sdk iphonesimulator \
buildBuild and run sample apps from the workspace:
AccountEditor:
- Basic CRUD operations on Account records
- Demonstrates Cordova plugin usage
MobileSyncExplorerHybrid:
- Complete MobileSync demo
- Offline sync, conflict resolution
- SmartStore integration
- Public API changes require a deprecation cycle. Deprecate in release N, remove no earlier than release N+2 (next major).
- No hardcoded secrets, tokens, or PII in source. Not even in test fixtures.
- Never log PII, refresh tokens, or full request/response bodies.
- Compiler warnings are bugs. Fix all warnings before submitting a PR.
- Localization: New user-facing strings must be added to
Localizable.strings.
- Objective-C for plugin bridges: Cordova plugins use Objective-C for compatibility
- Swift for new utilities: Non-plugin code can use Swift (e.g.,
SalesforceWebViewCookieManager.swift) - Cordova plugin conventions: Use
CDVPlugin,CDVInvokedUrlCommand, proper callback handling - WKWebView required: No UIWebView support (deprecated by Apple)
- Thread safety: Plugin methods may be called from any thread
- Memory management: Follow ARC conventions, careful with WKWebView retain cycles
- Classes/Structs/Protocols:
PascalCase(prefixSFfor Objective-C public types) - Functions/Methods/Properties:
camelCase - Cordova plugins: Prefix with
SalesforceorSF
- Framework: XCTest
- Location:
libs/SalesforceHybridSDK/SalesforceHybridSDKTests/ - Coverage target: 80% line coverage for new code
- Naming:
test_given[Precondition]_when[Action]_then[Expected]
SalesforceHybridSDK:
- Cordova plugin bridge methods (all plugins)
- View controller lifecycle and authentication flow
- Cookie management and session handling
- Local/remote hybrid view configurations
- Network connectivity monitoring
- Error handling and edge cases
SalesforceFileLogger:
- Log rotation and file management
- Log level filtering
- File export functionality
- Integration with CocoaLumberjack
Sample apps serve as integration tests:
- Build and run
AccountEditorto verify basic plugin functionality - Build and run
MobileSyncExplorerHybridfor complete sync workflows
When making changes that affect hybrid functionality:
- Modify iOS bridge in this repo (
libs/SalesforceHybridSDK/) - Modify Android bridge in Android repo (
libs/SalesforceHybrid/) - Modify JavaScript in Shared repo (if plugin interface changes)
- Update CordovaPlugin repo via
tools/update.sh - Test hybrid templates in Templates repo
- Run iOS unit tests for SalesforceHybridSDK
- Run Android unit tests in Android repo for SalesforceHybrid
- Verify sample apps work on both platforms
Important: A complete hybrid feature requires changes in multiple repos:
- This repo (iOS bridge)
- Android repo (Android bridge)
- Shared repo (JavaScript, if plugin interface changes)
- CordovaPlugin repo (update script to copy changes)
- Templates repo (if template updates needed)
When reviewing PRs:
- Both platforms updated: iOS and Android bridge both implement the change
- Backward compatibility: No breaking changes without deprecation cycle
- Shared repo updated: JavaScript interface matches native implementation
- Tests included: Unit tests for new functionality
- iOS tests pass: Run SalesforceHybridSDK test suite
- Android tests pass: Verify in Android repo
- Sample apps work: AccountEditor and MobileSyncExplorerHybrid still function
- No console warnings: No Xcode warnings or deprecation notices
- Documentation: Public APIs have header doc comments
- Templates work: Test with hybrid templates if API changed
- Submodules: Appropriate submodule versions referenced
- Always run unit tests before committing
- Test sample apps after making changes
- Check both iOS and Android implementations for consistency
- Update JavaScript in Shared repo when plugin interfaces change
- Reference iOS SDK CLAUDE.md for native SDK patterns
- Consider WKWebView threading and memory management
- Don't merge without human approval (public SDK)
- Don't modify submodule references without explicit request
- Don't change Cordova plugin interfaces without matching Android changes
- Don't add new dependencies without flagging for review
- Don't suppress warnings or test failures
- Don't modify
install.shwithout explicit request
- Any change to Cordova plugin interfaces
- OAuth flow, token storage, or credential handling changes
- WKWebView configuration or cookie management changes
- New public APIs or API signature modifications
- Build system changes (Xcode project, CocoaPods, podspecs)
- Dependency version bumps (Cordova, iOS SDK, CocoaLumberjack)
- Submodule reference updates
- Removal of any previously deprecated API
Understanding these concepts is essential:
- Cordova Plugin: Native iOS class (subclass of
CDVPlugin) that exposes methods to JavaScript - CDVInvokedUrlCommand: Cordova's wrapper for plugin method calls from JavaScript, includes callback IDs
- WKWebView: Modern WebKit view (required, UIWebView is deprecated)
- Hybrid View Config: Configuration specifying local vs remote app, authentication behavior
- Cookie Bridge: Mechanism to share Salesforce session cookies between native and WKWebView
- Bootstrap: Initial authentication and WebView setup before loading app content
- External Client App or Connected App (legacy): Salesforce OAuth configuration (defined in app, not in SDK)
- Localhost Substitution: Performance optimization for loading local files
- Pod name:
SalesforceHybridSDK - Registry: SalesforceMobileSDK-iOS-Specs (private podspec repo)
- Release process: Coordinated with iOS SDK releases
The CordovaPlugin repo references this repo and copies files during release:
cd SalesforceMobileSDK-CordovaPlugin
./tools/update.sh -b dev -o iosThis copies:
- iOS bridge code from
shared/hybrid/βsrc/ios/classes/ - Resources from iOS SDK β
src/ios/resources/
Hybrid templates depend on CordovaPlugin, which references this repo:
HybridLocalTemplate- Local HTML/JS appHybridRemoteTemplate- Remote Visualforce/Community app
- Mobile SDK Development Guide: https://developer.salesforce.com/docs/platform/mobile-sdk/guide
- iOS SDK: See
SalesforceMobileSDK-iOS/CLAUDE.mdfor native SDK details - Android Hybrid: See
SalesforceMobileSDK-Android/CLAUDE.md(libs/SalesforceHybrid section) - Shared JavaScript: See
SalesforceMobileSDK-Shared/CLAUDE.md - CordovaPlugin: See
SalesforceMobileSDK-CordovaPlugin/CLAUDE.md - Cordova iOS: https://cordova.apache.org/docs/en/latest/guide/platforms/ios/
- iOS Library References: https://forcedotcom.github.io/SalesforceMobileSDK-iOS