> ## Documentation Index
> Fetch the complete documentation index at: https://learn.social.plus/llms.txt
> Use this file to discover all available pages before exploring further.

# iOS Platform Guide

> Advanced iOS-specific features, optimizations, and best practices for social.plus UIKit

# iOS Platform Guide

This guide covers iOS-specific features, optimizations, and advanced configurations for social.plus UIKit. For basic installation, see our [Installation Guide](https://learn.social.plus/uikit/getting-started/installation.md#ios).

> [!NOTE]
>
> **Prerequisites**: iOS 12.0+, Xcode 12+, Swift 5.0+. Ensure you've completed the basic installation before following these advanced guides.

## Advanced Installation Options

### 🔧 **Custom Build Configurations**

Configure UIKit for different build environments:

**Debug Configuration**

```swift theme={null}
// AppDelegate.swift - Debug setup
#if DEBUG
AmityUIKitManager.setup(
    apiKey: "YOUR_DEBUG_API_KEY",
    region: .US,
    httpSettings: AmityHTTPSettings(
        enableLogging: true,
        logLevel: .verbose
    )
)
#endif
```

**Release Configuration**

```swift theme={null}
// AppDelegate.swift - Production setup
#if !DEBUG
AmityUIKitManager.setup(
    apiKey: "YOUR_PRODUCTION_API_KEY",
    region: .US,
    httpSettings: AmityHTTPSettings(
        enableLogging: false,
        logLevel: .error
    )
)
#endif
```

**Staging Configuration**

```swift theme={null}
// AppDelegate.swift - Staging setup
#if STAGING
AmityUIKitManager.setup(
    apiKey: "YOUR_STAGING_API_KEY",
    region: .EU,
    httpSettings: AmityHTTPSettings(
        enableLogging: true,
        logLevel: .info
    )
)
#endif
```

### 🎯 **Performance Optimizations**

#### Memory Management

```swift theme={null}
// Implement proper memory management
class ChatViewController: UIViewController {
    private var amityViewController: AmityChatViewController?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupAmityChat()
    }
    
    private func setupAmityChat() {
        amityViewController = AmityChatViewController()
        addChild(amityViewController!)
        view.addSubview(amityViewController!.view)
        amityViewController!.didMove(toParent: self)
    }
    
    deinit {
        // Clean up resources
        amityViewController?.willMove(toParent: nil)
        amityViewController?.view.removeFromSuperview()
        amityViewController?.removeFromParent()
    }
}
```

#### Image Caching Configuration

```swift theme={null}
// Configure image caching for better performance
AmityUIKitManager.configure { settings in
    settings.imageCacheSettings = AmityImageCacheSettings(
        memoryLimit: 50 * 1024 * 1024, // 50MB
        diskLimit: 200 * 1024 * 1024,   // 200MB
        diskAge: 60 * 60 * 24 * 7       // 1 week
    )
}
```

***

## iOS-Specific Features

### 📱 **Native iOS Integrations**

#### Push Notifications

```swift theme={null}
import UserNotifications

class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        // Setup UIKit
        AmityUIKitManager.setup(apiKey: "YOUR_API_KEY", region: .US)
        
        // Configure push notifications
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in
            if granted {
                DispatchQueue.main.async {
                    application.registerForRemoteNotifications()
                }
            }
        }
        
        return true
    }
    
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        // Register device token with Amity
        AmityUIKitManager.registerDeviceToken(deviceToken)
    }
}
```

#### Background App Refresh

```swift theme={null}
// Configure background refresh for real-time updates
func applicationDidEnterBackground(_ application: UIApplication) {
    AmityUIKitManager.enterBackground()
}

func applicationWillEnterForeground(_ application: UIApplication) {
    AmityUIKitManager.enterForeground()
}
```

#### Scene Delegate Support

```swift theme={null}
// SceneDelegate.swift - iOS 13+ multi-window support
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?
    
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let windowScene = (scene as? UIWindowScene) else { return }
        
        window = UIWindow(windowScene: windowScene)
        
        // Setup UIKit for this scene
        let mainViewController = MainViewController()
        window?.rootViewController = UINavigationController(rootViewController: mainViewController)
        window?.makeKeyAndVisible()
    }
}
```

### 🎨 **iOS Design System Integration**

#### Dynamic Type Support

```swift theme={null}
// Configure UIKit to support Dynamic Type
AmityUIKitManager.configure { settings in
    settings.accessibilitySettings = AmityAccessibilitySettings(
        supportDynamicType: true,
        minimumFontSize: 12.0,
        maximumFontSize: 24.0
    )
}
```

#### Dark Mode Support

```swift theme={null}
// Automatic dark mode detection
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
    super.traitCollectionDidChange(previousTraitCollection)
    
    if traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) {
        // Update UIKit theme based on system appearance
        let isDarkMode = traitCollection.userInterfaceStyle == .dark
        AmityUIKitManager.setTheme(isDarkMode ? .dark : .light)
    }
}
```

#### Safe Area Handling

```swift theme={null}
// Proper safe area integration
class ContainerViewController: UIViewController {
    private let amityViewController = AmityFeedViewController()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        addChild(amityViewController)
        view.addSubview(amityViewController.view)
        
        amityViewController.view.translatesAutoresizingMaskIntoConstraints = false
        NSLayoutConstraint.activate([
            amityViewController.view.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
            amityViewController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
            amityViewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
            amityViewController.view.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
        ])
        
        amityViewController.didMove(toParent: self)
    }
}
```

***

## Advanced Customization

### 🎭 **Custom Theming**

#### Brand Color Integration

```swift theme={null}
// Custom color scheme
let customTheme = AmityTheme()
customTheme.primaryColor = UIColor(red: 0.2, green: 0.4, blue: 0.8, alpha: 1.0)
customTheme.secondaryColor = UIColor(red: 0.1, green: 0.2, blue: 0.4, alpha: 1.0)
customTheme.backgroundColor = UIColor.systemBackground
customTheme.textColor = UIColor.label

AmityUIKitManager.setCustomTheme(customTheme)
```

#### Typography Customization

```swift theme={null}
// Custom fonts
let customTypography = AmityTypography()
customTypography.headingFont = UIFont(name: "YourCustomFont-Bold", size: 18) ?? UIFont.systemFont(ofSize: 18, weight: .bold)
customTypography.bodyFont = UIFont(name: "YourCustomFont-Regular", size: 16) ?? UIFont.systemFont(ofSize: 16)
customTypography.captionFont = UIFont(name: "YourCustomFont-Light", size: 14) ?? UIFont.systemFont(ofSize: 14, weight: .light)

AmityUIKitManager.setCustomTypography(customTypography)
```

### 🔧 **Component Customization**

#### Custom Navigation Bar

```swift theme={null}
class CustomFeedViewController: AmityFeedViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Customize navigation bar
        navigationItem.title = "My Social Feed"
        navigationController?.navigationBar.prefersLargeTitles = true
        
        // Add custom buttons
        let profileButton = UIBarButtonItem(
            image: UIImage(systemName: "person.circle"),
            style: .plain,
            target: self,
            action: #selector(showProfile)
        )
        navigationItem.rightBarButtonItem = profileButton
    }
    
    @objc private func showProfile() {
        let profileVC = AmityUserProfileViewController()
        present(profileVC, animated: true)
    }
}
```

#### Custom Cell Layouts

```swift theme={null}
// Register custom cell classes
class CustomizedFeedViewController: AmityFeedViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Register custom post cell
        registerCustomPostCell(CustomPostTableViewCell.self, forCellType: .text)
        registerCustomPostCell(CustomImagePostTableViewCell.self, forCellType: .image)
    }
}

class CustomPostTableViewCell: AmityPostTableViewCell {
    override func setupCustomLayout() {
        super.setupCustomLayout()
        
        // Add custom UI elements
        contentView.backgroundColor = UIColor.systemGray6
        contentView.layer.cornerRadius = 12
        contentView.layer.masksToBounds = true
    }
}
```

***

## Debugging & Troubleshooting

### 🐛 **Common iOS Issues**

> **Build Errors**
>
> **Issue**: Build fails with dependency conflicts
>
> **Solutions**:
>
> 1. Clean build folder: `Cmd + Shift + K`
> 2. Delete derived data: `~/Library/Developer/Xcode/DerivedData`
> 3. Reset package cache: Xcode → File → Packages → Reset Package Caches
> 4. Verify deployment target matches UIKit requirements (iOS 12.0+)
>
> ```bash theme={null}
> # Terminal command to clean derived data
> rm -rf ~/Library/Developer/Xcode/DerivedData
> ```

> **Runtime Crashes**
>
> **Issue**: App crashes when loading UIKit components
>
> **Solutions**:
>
> 1. Verify API key is valid and properly set
> 2. Check network connectivity
> 3. Enable debug logging to see detailed error messages
> 4. Ensure proper memory management
>
> ```swift theme={null}
> // Enable detailed logging
> AmityUIKitManager.setLogLevel(.verbose)
> ```

> **UI Layout Issues**
>
> **Issue**: Components don't display correctly
>
> **Solutions**:
>
> 1. Check auto-layout constraints
> 2. Verify safe area handling
> 3. Test on different device sizes
> 4. Check for custom theme conflicts
>
> ```swift theme={null}
> // Debug view hierarchy
> override func viewDidAppear(_ animated: Bool) {
>     super.viewDidAppear(animated)
>     view.debugSubviews() // Custom debug method
> }
> ```

### 📊 **Performance Monitoring**

```swift theme={null}
// Monitor UIKit performance
class PerformanceMonitor {
    static func trackComponentLoad(componentName: String) {
        let startTime = CFAbsoluteTimeGetCurrent()
        
        // Component loading logic
        
        let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
        print("Component \(componentName) loaded in \(timeElapsed) seconds")
    }
}

// Usage
PerformanceMonitor.trackComponentLoad(componentName: "AmityFeedViewController")
```

***

## Production Deployment

### 🚀 **App Store Preparation**

#### Info.plist Configuration

```xml theme={null}
<!-- Required permissions -->
<key>NSCameraUsageDescription</key>
<string>This app uses camera to capture photos for posts and profile pictures</string>

<key>NSPhotoLibraryUsageDescription</key>
<string>This app accesses photo library to select images for posts</string>

<key>NSMicrophoneUsageDescription</key>
<string>This app uses microphone for voice messages and video calls</string>
```

#### Build Configuration

```swift theme={null}
// Production-ready configuration
#if !DEBUG
AmityUIKitManager.setup(
    apiKey: "PRODUCTION_API_KEY",
    region: .US,
    httpSettings: AmityHTTPSettings(
        enableLogging: false,
        logLevel: .error,
        enableCrashReporting: true
    )
)
#endif
```

### 📈 **Analytics Integration**

```swift theme={null}
// Custom analytics tracking
extension AmityUIKitManager {
    static func trackUserAction(_ action: String, parameters: [String: Any] = [:]) {
        // Your analytics service integration
        Analytics.track(action, properties: parameters)
    }
}

// Usage in custom view controllers
class AnalyticsEnabledFeedViewController: AmityFeedViewController {
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        AmityUIKitManager.trackUserAction("feed_viewed")
    }
}
```

***

## Resources & Best Practices

### 📚 **Recommended Architecture**

```swift theme={null}
// MVVM pattern with UIKit
class FeedViewModel: ObservableObject {
    @Published var posts: [AmityPost] = []
    private let amityDataSource = AmityFeedDataSource()
    
    func loadPosts() {
        amityDataSource.loadPosts { [weak self] posts in
            DispatchQueue.main.async {
                self?.posts = posts
            }
        }
    }
}

class FeedViewController: UIViewController {
    private let viewModel = FeedViewModel()
    private let amityFeedView = AmityFeedView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupBindings()
        viewModel.loadPosts()
    }
    
    private func setupBindings() {
        viewModel.$posts.sink { [weak self] posts in
            self?.amityFeedView.updatePosts(posts)
        }.store(in: &cancellables)
    }
}
```

### 🔗 **Additional Resources**

> **[iOS Sample App](https://github.com/AmityCo/Amity-Social-UIKit-iOS-Sample)**
>
> Complete iOS sample application with best practices

> **[iOS Documentation](https://learn.social.plus/uikit/components/overview.md)**
>
> Detailed component documentation for iOS

> **[Customization Overview](https://learn.social.plus/uikit/customization/overview.md)**
>
> End-to-end guide to theming & customizing UIKit

> **[Theming Basics](https://learn.social.plus/uikit/customization/component-styling.md)**
>
> Learn how to apply brand colors & typography

> [!TIP]
>
> **Need Help?** Join our [iOS developers community](https://community.socialplus.com/ios) for platform-specific discussions and support.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.