|
| 1 | +# iOS Setup Guide |
| 2 | + |
| 3 | +## SPM Framework Embedding Required |
| 4 | + |
| 5 | +QuickCrypto uses Swift Package Manager (SPM) dependencies that must be manually embedded in your app bundle: |
| 6 | + |
| 7 | +- **OpenSSL 3.6+** (required) - For ML-DSA post-quantum cryptography support |
| 8 | +- **Sodium** (optional) - For XSalsa20 cipher support via libsodium (when `SODIUM_ENABLED=1`) |
| 9 | + |
| 10 | +### Why is this needed? |
| 11 | + |
| 12 | +CocoaPods doesn't automatically embed SPM frameworks into the final app bundle. Without this configuration, you'll encounter runtime errors: |
| 13 | + |
| 14 | +``` |
| 15 | +dyld: Library not loaded: @rpath/OpenSSL.framework/OpenSSL |
| 16 | +``` |
| 17 | + |
| 18 | +This is a temporary limitation of mixing CocoaPods + SPM. It will be resolved when React Native fully migrates to SPM (expected 2026). |
| 19 | + |
| 20 | +## Configuration |
| 21 | + |
| 22 | +Add the following to your `ios/Podfile` inside the `post_install` hook: |
| 23 | + |
| 24 | +```ruby |
| 25 | +post_install do |installer| |
| 26 | + # ... your existing post_install code (react_native_post_install, etc.) ... |
| 27 | + |
| 28 | + # Embed SPM frameworks from QuickCrypto |
| 29 | + main_project_path = File.join(installer.sandbox.root.parent, 'YourAppName.xcodeproj') |
| 30 | + main_project = Xcodeproj::Project.open(main_project_path) |
| 31 | + app_target = main_project.targets.find { |t| t.name == 'YourAppName' } |
| 32 | + |
| 33 | + if app_target |
| 34 | + embed_phase_name = 'Embed SPM Frameworks (QuickCrypto)' |
| 35 | + existing_phase = app_target.shell_script_build_phases.find { |p| p.name == embed_phase_name } |
| 36 | + |
| 37 | + unless existing_phase |
| 38 | + phase = app_target.new_shell_script_build_phase(embed_phase_name) |
| 39 | + phase.shell_script = <<~SCRIPT |
| 40 | + mkdir -p "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}" |
| 41 | +
|
| 42 | + # Embed OpenSSL.framework (required for ML-DSA) |
| 43 | + if [ -d "${BUILT_PRODUCTS_DIR}/OpenSSL.framework" ]; then |
| 44 | + rsync -av --delete "${BUILT_PRODUCTS_DIR}/OpenSSL.framework" "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/" |
| 45 | + if [ -n "${EXPANDED_CODE_SIGN_IDENTITY:-}" ]; then |
| 46 | + /usr/bin/codesign --force --sign "${EXPANDED_CODE_SIGN_IDENTITY}" --preserve-metadata=identifier,entitlements "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/OpenSSL.framework" |
| 47 | + fi |
| 48 | + fi |
| 49 | +
|
| 50 | + # Embed Sodium.framework (optional, if SODIUM_ENABLED=1) |
| 51 | + if [ -d "${BUILT_PRODUCTS_DIR}/Sodium.framework" ]; then |
| 52 | + rsync -av --delete "${BUILT_PRODUCTS_DIR}/Sodium.framework" "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/" |
| 53 | + if [ -n "${EXPANDED_CODE_SIGN_IDENTITY:-}" ]; then |
| 54 | + /usr/bin/codesign --force --sign "${EXPANDED_CODE_SIGN_IDENTITY}" --preserve-metadata=identifier,entitlements "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Sodium.framework" |
| 55 | + fi |
| 56 | + fi |
| 57 | + SCRIPT |
| 58 | + |
| 59 | + # Insert before the CocoaPods embed frameworks phase |
| 60 | + embed_pods_phase = app_target.shell_script_build_phases.find { |p| p.name == '[CP] Embed Pods Frameworks' } |
| 61 | + if embed_pods_phase |
| 62 | + app_target.build_phases.move(phase, app_target.build_phases.index(embed_pods_phase)) |
| 63 | + end |
| 64 | + |
| 65 | + main_project.save |
| 66 | + end |
| 67 | + end |
| 68 | +end |
| 69 | +``` |
| 70 | + |
| 71 | +**Important:** Replace `YourAppName` with your actual Xcode target name (usually matches your app name). |
| 72 | + |
| 73 | +## Example |
| 74 | + |
| 75 | +See the [example app's Podfile](../../example/ios/Podfile) for a complete working reference. |
| 76 | + |
| 77 | +## Enabling libsodium (Optional) |
| 78 | + |
| 79 | +To enable XSalsa20 cipher support, set the environment variable before installing pods: |
| 80 | + |
| 81 | +```ruby |
| 82 | +# At the top of your Podfile |
| 83 | +ENV['SODIUM_ENABLED'] = '1' |
| 84 | +``` |
| 85 | + |
| 86 | +Then run: |
| 87 | + |
| 88 | +```bash |
| 89 | +cd ios && pod install |
| 90 | +``` |
| 91 | + |
| 92 | +## Troubleshooting |
| 93 | + |
| 94 | +### Error: "Library not loaded: @rpath/OpenSSL.framework/OpenSSL" |
| 95 | + |
| 96 | +This means the SPM frameworks aren't being embedded. Verify: |
| 97 | + |
| 98 | +1. The `post_install` hook is properly configured in your Podfile |
| 99 | +2. You're using `use_frameworks! :linkage => :dynamic` (required for SPM dependencies) |
| 100 | +3. Run `cd ios && pod install` after modifying the Podfile |
| 101 | +4. Clean build folder in Xcode (Cmd+Shift+K) and rebuild |
| 102 | + |
| 103 | +### Dynamic Frameworks Required |
| 104 | + |
| 105 | +QuickCrypto requires dynamic framework linking due to SPM dependencies. Add this to your Podfile: |
| 106 | + |
| 107 | +```ruby |
| 108 | +use_frameworks! :linkage => :dynamic |
| 109 | +``` |
| 110 | + |
| 111 | +## Future |
| 112 | + |
| 113 | +When React Native completes its migration to Swift Package Manager (expected 2026), this manual embedding step will no longer be necessary. SPM packages will be properly integrated by default. |
0 commit comments