Skip to content

Installation

Latisha. edited this page Dec 27, 2024 · 1 revision

Installation Guide

This guide walks you through setting up LibDC-Swift in your iOS or macOS project.

System Requirements

Development Environment

  • Xcode 15.0 or later
  • Swift 5.10 or later
  • iOS 15.0+ / macOS 12.0+

Device Requirements

  • iOS device with BLE capability
  • macOS device with BLE capability
  • Physical access to supported dive computer

Required Capabilities

  • bluetooth-le capability in your app's entitlements
  • Privacy usage description for Bluetooth in Info.plist

Installation Steps

Using Swift Package Manager

  1. In Xcode, open your project and select File → Add Packages...

  2. Enter the package repository URL:

https://latishab/LibDC-Swift.git
  1. Select the version rule:

    • Up to Next Major (recommended)
    • Up to Next Minor
    • Exact Version
  2. Add the package to your target

Manual Installation

  1. Clone the repository:
git clone https://latishab/LibDC-Swift.git
  1. Drag the LibDC-Swift folder into your Xcode project

  2. In the "Add files" dialog:

    • Check "Copy items if needed"
    • Create groups for added folders
    • Add to your target

Basic Configuration

1. Add Required Info.plist Entries

<key>NSBluetoothAlwaysUsageDescription</key>
<string>This app needs Bluetooth to connect to dive computers</string>

<key>NSBluetoothPeripheralUsageDescription</key>
<string>This app needs Bluetooth to connect to dive computers</string>

2. Initialize in Your App

import LibDCSwift

@main
struct YourApp: App {
    @StateObject private var bleManager = CoreBluetoothManager.shared
    
    var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(bleManager)
        }
    }
}

3. Basic Usage Setup

import LibDCSwift

struct ContentView: View {
    @EnvironmentObject var bleManager: CoreBluetoothManager
    @StateObject var diveDataVM = DiveDataViewModel()
    
    var body: some View {
        // Your view content
    }
}

Troubleshooting Common Issues

Bluetooth Not Working

  1. Check Bluetooth permissions:

    • Verify Info.plist entries
    • Check app permissions in device settings
    • Ensure Bluetooth is enabled on device
  2. Debug steps:

// Enable detailed logging
Logger.shared.setMinLevel(.debug)
Logger.shared.setShowRawData(true)

Connection Issues

  1. Device not appearing:

    • Ensure device is in pairing mode
    • Check device battery level
    • Verify device support in documentation
    • Go to your iOS bluetooth settings, and forget device for the dive computer you have connected
  2. Connection failing:

// Enable connection logging
bleManager.setLogging(enabled: true)

// Monitor connection state
bleManager.$connectedDevice
    .sink { device in
        if device == nil {
            print("Connection lost or failed")
        }
    }

Build Issues

  1. Package Resolution Fails:

    • Clean build folder (Shift + Cmd + K)
    • Clean package cache:
      rm -rf ~/Library/Caches/org.swift.swiftpm/
    • Update package references
  2. Library Not Found:

    • Verify target membership
    • Check framework embedding
    • Rebuild project

Permission Issues

  1. Missing Bluetooth Permission:
// Check authorization status
if CBCentralManager.authorization == .allowedAlways {
    // Proceed with BLE operations
} else {
    // Handle unauthorized state
}
  1. Background Operation Issues:
    • Add required background modes to Info.plist
    • Implement proper state restoration

Next Steps

After successful installation:

  1. Review the Usage Guide for basic operations
  2. Check Device Support for your specific dive computer
  3. Explore API Reference for detailed documentation

Getting Help

If you encounter issues not covered here:

  1. Check the GitHub Issues for similar problems
  2. Create a new issue with:
    • Detailed problem description
    • Steps to reproduce
    • Environment information
    • Relevant code snippets
Clone this wiki locally