# `Dala.Setup.Ios`
[🔗](https://github.com/manhvu/dala/blob/main/lib/dala/setup/ios.ex#L1)

iOS Bluetooth/WiFi setup automation for Dala.

This module provides automated setup for iOS Bluetooth and WiFi functionality
by configuring the Xcode project with required files, frameworks, and
Info.plist entries.

## Usage

From the command line (via Mix task):

    mix dala.setup_ios_bluetooth
    mix dala.setup_ios_bluetooth --check

From Elixir code:

    Dala.Setup.IOS.setup_bluetooth()
    Dala.Setup.IOS.setup_bluetooth("/path/to/ios/directory")
    Dala.Setup.IOS.check("/path/to/ios/directory")

## What it does

1. Finds the Xcode project or workspace in the ios/ directory
2. Adds Bluetooth files to the Xcode project:
   - DalaBluetoothManager.h
   - DalaBluetoothManager.m
   - DalaBluetoothCInterface.m
   - DalaBluetooth.swift
3. Links CoreBluetooth.framework
4. Adds required keys to Info.plist:
   - NSBluetoothAlwaysUsageDescription
   - NSBluetoothPeripheralUsageDescription
   - NSLocalNetworkUsageDescription
   - NSBonjourServices
   - UIBackgroundModes (bluetooth-central)
5. Patches AppDelegate to call DalaBluetoothBridge.ensureLinked()
6. Verifies the setup

## Prerequisites

- Xcode project must exist in the ios/ directory
- Ruby is preferred (for pbxproj modification); sed fallback if unavailable
- plutil or PlistBuddy must be available (for Info.plist modification)

# `result`

```elixir
@type result() :: {:ok, String.t()} | {:error, String.t()}
```

# `bluetooth_files_present?`

```elixir
@spec bluetooth_files_present?(String.t() | nil) :: boolean()
```

Check if Bluetooth files are present in the ios/ directory.

# `check`

```elixir
@spec check(String.t() | nil) :: result()
```

Verify the current iOS Bluetooth/WiFi setup without making changes.

Returns `{:ok, message}` if all checks pass, `{:error, reason}` otherwise.

# `find_xcode_project`

```elixir
@spec find_xcode_project(String.t() | nil) :: {:ok, String.t()} | {:error, String.t()}
```

Find the Xcode project or workspace in the given directory.

# `print_instructions`

```elixir
@spec print_instructions() :: :ok
```

Print setup instructions without running the script.

# `setup_bluetooth`

```elixir
@spec setup_bluetooth(String.t() | nil) :: result()
```

Run the iOS Bluetooth/WiFi setup.

Returns `{:ok, message}` on success, `{:error, reason}` on failure.

# `xcode_project_exists?`

```elixir
@spec xcode_project_exists?(String.t() | nil) :: boolean()
```

Check if an Xcode project exists in the given directory.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
