Delta Chat iOS Client

repository·main·Indexed 19 days ago

https://github.com/deltachat/deltachat-ios

The official iOS implementation of the Delta Chat messenger, utilizing a Rust-based core library. This documentation covers building the project with Xcode, installing prerequisites like rustup and CocoaPods, managing Apple Push Services Certificates, and understanding the app's UIKit view hierarchy, coordinator patterns, and Swift Testing suite.

Tokens
2.8K
Snippets
8
Records
18
Agent score
66%

What's inside deltachat-ios

  1. Understand UIKit view hierarchy and controllers

    main

    The project uses standard UIKit components to build the user interface. Understanding these core abstractions is essential for navigating the codebase:

    • UIView: The basic building block for all UI elements (buttons, labels, layouts). It represents a rectangular area and can contain other UIView objects.
    • UIViewController: Manages a single view (or a hierarchy of views). It is the primary unit for managing screen logic, similar to an Android Activity.
    • UINavigationController: Manages a stack of UIViewController objects and provides a navigation bar. It handles transitions between screens using pushViewController() and popViewController().
    • UITabBarController: Manages multiple view controllers accessible via a bottom tab bar.
    • UIWindow: The backdrop for the UI that dispatches events. The window.rootViewController serves as the anchor for the entire application's view hierarchy.
  2. Understand the Application lifecycle and entry point

    main

    The application lifecycle is managed through the following components:

    • UIApplication: The single instance representing the app. It is initialized via UIApplicationMain() or the @UIApplicationMain attribute.
    • UIApplicationDelegate: A delegate that responds to application-level events (e.g., application(_:didFinishLaunchingWithOptions:)). This is the ideal place to store "app globals" like DcContext.
    • UIApplication.shared.delegate: Provides access to the application's delegate instance.
  3. How delegates and coordinators work in the app

    main

    The application uses two main patterns for flow control and navigation:

    Delegation

    Delegation is used to receive events from the system or other components. A "delegator" calls specific functions on a "delegate" (defined by a protocol) when an event occurs (e.g., didSelect()).

    Coordinators

    Coordinators are a convention used to decouple navigation logic from View Controllers.

    • A coordinator typically takes a UINavigationController during construction.
    • It handles navigation by calling methods like pushViewController().
    • In this project, strong references are held to coordinators, which in turn hold strong references to the view controllers they manage. This ensures the navigation stack is not prematurely deallocated.
    • While coordinators help reuse logic by removing navigation responsibility from views, the project notes that they can add complexity if overused.
  4. Create the `.cer` file via Apple Developer Portal

    main

    Once you have the signing request, generate the Apple certificate:

    1. Go to the Apple Certificate Resources page.
    2. Click Create.
    3. Select Apple Push Notification service SSL (Sandbox & Production).
    4. For App ID, use: 8Y...A8.chat.delta.
    5. Upload the CertificateSigningRequest.certSigningRequest file created in the previous step.
    6. Download the resulting file and save it locally as certificates/YEAR-push-renew-NUMBER/aps.cer.

    Note: Do not commit this file to git.

  5. Run tests in deltachat-ios

    main

    To run the full test suite in Xcode, ensure the deltachat-ios target is selected. Long-press the Run button (the play icon) at the top of the Xcode interface and select Test from the menu to switch the action from running the app to running tests.

    To run a specific individual test, navigate to the desired test function within the DcTests.swift file. Click the Test button (the diamond icon) located in the gutter (the line number column) next to the first line of the test function.

  6. Install prerequisites for building Delta Chat iOS

    main

    Before building the project, you must install rustup, cargo-lipo, and CocoaPods.

    # Install rustup
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    
    # Install cargo-lipo
    cargo install cargo-lipo
    
    # Install CocoaPods (via Homebrew)
    brew install cocoapods
  7. Setup the workspace and build with Xcode

    main

    Follow these steps to clone the repository, initialize submodules, install the required Rust toolchain, and set up CocoaPods dependencies.

    Note: Always open the .xcworkspace file, not the .xcodeproj file, to run the project.

    # Clone and initialize
    git clone git@github.com:deltachat/deltachat-ios.git
    cd deltachat-ios
    git submodule update --init --recursive
    
    # Install specific Rust toolchain
    rustup toolchain install `cat rust-toolchain`
    
    # Install CocoaPods dependencies
    pod install
    
    # Open the workspace in Xcode
    open deltachat-ios.xcworkspace
  8. Create a Certificate Signing Request (CSR)

    main

    To begin the renewal, generate a signing request on a Mac desktop:

    1. Launch the Keychain Access app.
    2. In the main menu, navigate to: Keychain Access > Certificate Assistant > Request a Certificate from a Certificate Authority.
    3. Use the following details:
      • Email Address: delta-ios@merlinux.eu
      • Common Name: delta-apns
    4. Save the file locally as certificates/YEAR-push-renew-NUMBER/CertificateSigningRequest.certSigningRequest.

    Note: Do not commit this file to git.

  9. Replace help images with iOS-specific versions

    main

    The scripts/local-help-image-replacements directory contains alternative versions of help images from https://delta.chat/help that are designed to look more native to iOS.

    To apply these replacements to the generated offline help, run the following script:

    ./script/create-local-help.sh

    This script copies the images from this directory into the generated offline help, overwriting the original images. You do not need to replace every image; only replace those that do not align with the iOS aesthetic. The general goal is to maintain neutral images where possible, but use these replacements for images that feel non-native to the iOS platform.

  10. Convert `.cer` to `.p12` using Keychain Access

    main

    To prepare the certificate for the server, convert the .cer file into a .p12 format:

    1. Create a file named certificates/YEAR-push-renew-NUMBER/password.txt containing only a secure password.
    2. In Keychain Access, select the login keychain and the Certificates tab.
    3. Go to File > Import Items... and select your aps.cer file.
    4. Locate the newly imported item (look for the one with the furthest expiration date) and expand it.
    5. Select the delta-apns certificate.
    6. Right-click and select Export "delta-apns".
    7. Save the file as certificates/YEAR-push-renew-NUMBER/Certificates.p12.
    8. When prompted, enter the password you saved in password.txt.