Skip to content

Latest commit

Β 

History

History
364 lines (292 loc) Β· 13.9 KB

File metadata and controls

364 lines (292 loc) Β· 13.9 KB

CLAUDE.md β€” Salesforce Mobile SDK for iOS Hybrid


About This Project

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.

iOS Hybrid Architecture

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

Repository Structure

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

Libraries

SalesforceHybridSDK

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

SalesforceFileLogger

Purpose: File-based logging for hybrid apps

Features:

  • Log rotation and management
  • Configurable log levels
  • Log file export for debugging
  • Integration with CocoaLumberjack

Dependencies

CocoaPods Dependencies

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 framework

Git Submodules

external/SalesforceMobileSDK-iOS    # iOS native SDK
external/shared                      # Shared JavaScript libraries
external/cordova                     # Apache Cordova iOS
external/CocoaLumberjack            # Logging library

Build & Test Setup

Prerequisites

  • macOS: Required for iOS development
  • Xcode: 15+ recommended
  • iOS: Minimum deployment target 18.0
  • CocoaPods: For dependency management

Initial Setup

# 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.xcworkspace

Important: Always open .xcworkspace, not .xcodeproj files.

Build Commands

# 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 \
  build

Sample Apps

Build 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

Code Standards

General Rules (Both Platforms)

  • 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.

iOS-Specific (Hybrid)

  • 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

Naming Conventions

  • Classes/Structs/Protocols: PascalCase (prefix SF for Objective-C public types)
  • Functions/Methods/Properties: camelCase
  • Cordova plugins: Prefix with Salesforce or SF

Testing Standards

Unit Tests

  • Framework: XCTest
  • Location: libs/SalesforceHybridSDK/SalesforceHybridSDKTests/
  • Coverage target: 80% line coverage for new code
  • Naming: test_given[Precondition]_when[Action]_then[Expected]

What to Test

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

Integration Tests

Sample apps serve as integration tests:

  • Build and run AccountEditor to verify basic plugin functionality
  • Build and run MobileSyncExplorerHybrid for complete sync workflows

Cross-Platform Change Workflow

When making changes that affect hybrid functionality:

  1. Modify iOS bridge in this repo (libs/SalesforceHybridSDK/)
  2. Modify Android bridge in Android repo (libs/SalesforceHybrid/)
  3. Modify JavaScript in Shared repo (if plugin interface changes)
  4. Update CordovaPlugin repo via tools/update.sh
  5. Test hybrid templates in Templates repo
  6. Run iOS unit tests for SalesforceHybridSDK
  7. Run Android unit tests in Android repo for SalesforceHybrid
  8. 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)

Code Review Checklist

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

Agent Behavior Guidelines

Do

  • 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

  • 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.sh without explicit request

Escalation β€” Stop and Flag for Human Review

  • 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

Key Domain Concepts

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

Release & Distribution

CocoaPods Distribution

  • Pod name: SalesforceHybridSDK
  • Registry: SalesforceMobileSDK-iOS-Specs (private podspec repo)
  • Release process: Coordinated with iOS SDK releases

Submodule in CordovaPlugin

The CordovaPlugin repo references this repo and copies files during release:

cd SalesforceMobileSDK-CordovaPlugin
./tools/update.sh -b dev -o ios

This copies:

  • iOS bridge code from shared/hybrid/ β†’ src/ios/classes/
  • Resources from iOS SDK β†’ src/ios/resources/

Template Integration

Hybrid templates depend on CordovaPlugin, which references this repo:

  • HybridLocalTemplate - Local HTML/JS app
  • HybridRemoteTemplate - Remote Visualforce/Community app

Related Documentation