> ## 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

> Get up and running with social.plus iOS SDK for Swift applications in minutes.

Get your iOS app connected to social.plus in just a few steps. This guide covers everything from installation to your first authenticated session.

## Requirements

* Xcode 26.0+
* iOS 14.0+
* Swift 5.0+

## Installation

<Tabs>
  <Tab title="Swift Package Manager (Recommended)">
    Add the social.plus SDK to your project using Swift Package Manager:

    1. In Xcode, select **File** → **Add Package Dependencies**
    2. Enter the repository URL:

       ```
       https://github.com/AmityCo/Amity-Social-Cloud-SDK-iOS-SwiftPM
       ```
    3. Select **Up to Next Major Version** and click **Add Package**
    4. Choose **AmitySDK** and click **Add Package**

    <Warning>
      Use "Up to Next Major Version" to ensure compatibility with future updates.
    </Warning>
  </Tab>

  <Tab title="Manual Installation">
    1. [Download the latest iOS SDK](https://sdk.amity.co/sdk-release/ios/amitysdk.zip)
    2. Drag `AmitySDK.xcframework` to your project
    3. Select **Copy items if needed** and click **Finish**
    4. Set the **Embed** option to **Embed & Sign**

    <Note>
      For M1 Macs using the simulator, enable Rosetta mode for the application.
    </Note>
  </Tab>
</Tabs>

## Parameters

| Operation                | Parameter           | Required   | Description                                                     |
| ------------------------ | ------------------- | ---------- | --------------------------------------------------------------- |
| Initialize SDK           | API key             | Yes        | Application API key from the social.plus Console.               |
| Initialize SDK           | Region              | Yes        | Region passed to `AmityClient`, such as `.US`, `.EU`, or `.SG`. |
| Objective-C bridge login | `userId`            | Yes        | Stable user identifier from your identity system.               |
| Objective-C bridge login | `displayName`       | No         | Display name passed through the Swift bridge.                   |
| Objective-C bridge login | `authToken`         | Production | Backend-generated auth token passed through the Swift bridge.   |
| Objective-C bridge login | Completion callback | Yes        | Callback that reports success or failure back to Objective-C.   |

## Initialize the SDK

Create the client with your API key and region so the SDK is ready for authentication.

<CodeGroup>
  ```swift iOS theme={null}
  import AmitySDK

  let client = try! AmityClient(apiKey: "YOUR_API_KEY", region: .SG)
  ```
</CodeGroup>

<Info>
  This creates the SDK client but does not yet authenticate a user. See [Authentication](/social-plus-sdk/getting-started/authentication) for the next step.
</Info>

## Objective-C Integration

<Info>
  Starting with v6.0.0, AmitySDK for iOS is written in **Pure Swift**. You can still use it in Objective-C projects by creating a **Mixed-Language Project**.
</Info>

<Warning>
  We recommend integrating AmitySDK directly into your Objective-C project and using **Swift language** to call the SDK interfaces for better compatibility and performance.
</Warning>

### Mixed Language Project Setup

Create Swift files with necessary interfaces/methods that interact with AmitySDK. These interfaces should be exposed with `@objc` or `@objcMembers` attributes.

When you add a new Swift file to your Objective-C project, Xcode automatically generates a bridging header file that exposes your Swift code to Objective-C.

<Note>
  📖 **Learn More**: [Importing Swift into Objective-C - Apple Developer](https://developer.apple.com/documentation/swift/importing-swift-into-objective-c)
</Note>

### Implementation Example

<Tabs>
  <Tab title="Swift Bridge File">
    Create a Swift file that wraps AmitySDK functionality:

    <CodeGroup>
      ```swift theme={null}
      // SDKLoginManager.swift
      // Example of a Swift file which contains a class to interact with AmitySDK

      import AmitySDK

      class NoopSessionHandler: SessionHandler {
          func sessionWillRenewAccessToken(renewal: any AccessTokenRenewal) {}
      }

      @objc class SDKLoginManager: NSObject {
          
          let client: AmityClient?
          
          @objc init(apiKey: String) {
              self.client = try? AmityClient(apiKey: apiKey)
          }
          
          @objc func login(userId: String, displayName: String, authToken: String, completion: @escaping (Bool, Error?) -> Void) {
              Task {
                  do {
                      try await self.client?.login(
                          userId: userId,
                          displayName: displayName.isEmpty ? nil : displayName,
                          authToken: authToken.isEmpty ? nil : authToken,
                          sessionHandler: NoopSessionHandler()
                      )
                      completion(true, nil)
                  } catch {
                      completion(false, error)
                  }
              }
          }
          
          @objc func logout() {
              Task { try? await self.client?.secureLogout() }
          }
          
          @objc func isLoggedIn() -> Bool {
              guard let state = self.client?.sessionState else { return false }
              if case .established = state { return true }
              return false
          }
          
          @objc func getCurrentUserId() -> String? {
              return self.client?.currentUserId ?? nil
          }
      }
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Objective-C Usage">
    Use the Swift bridge in your Objective-C code:

    ```objc theme={null}
    // ViewController.m
    #import "ViewController.h"
    #import "YourProjectName-Swift.h" // <- This import exposes your Swift file

    @interface ViewController ()
    @property (nonatomic, strong) SDKLoginManager *loginManager;
    @end

    @implementation ViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
        
        // Initialize the SDK manager
        self.loginManager = [[SDKLoginManager alloc] initWithApiKey:@"your-api-key"];
    }

    - (void)performLogin {
        [self.loginManager loginWithUserId:@"user-123" 
                               displayName:@"John Doe" 
                                 authToken:@"your-auth-token" 
                                completion:^(BOOL isSuccess, NSError * _Nullable error) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                if (isSuccess) {
                    NSLog(@"Login successful");
                    // Navigate to main app
                    [self showMainApp];
                } else {
                    NSLog(@"Login failed: %@", error.localizedDescription);
                    // Show error message
                    [self showErrorAlert:error.localizedDescription];
                }
            });
        }];
    }

    - (void)performLogout {
        [self.loginManager logout];
        NSLog(@"User logged out");
    }

    - (void)checkLoginStatus {
        if ([self.loginManager isLoggedIn]) {
            NSString *userId = [self.loginManager getCurrentUserId];
            NSLog(@"User is logged in: %@", userId);
        } else {
            NSLog(@"User is not logged in");
        }
    }

    // Helper methods
    - (void)showMainApp {
        // Your navigation logic here
    }

    - (void)showErrorAlert:(NSString *)message {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Login Error"
                                                                       message:message
                                                                preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK"
                                                           style:UIAlertActionStyleDefault
                                                         handler:nil];
        [alert addAction:okAction];
        
        [self presentViewController:alert animated:YES completion:nil];
    }

    @end
    ```
  </Tab>
</Tabs>

### Key Considerations

<AccordionGroup>
  <Accordion title="Project Configuration" icon="gear">
    **Bridging Header**: Xcode automatically creates a bridging header when you add Swift files to an Objective-C project.

    **Import Statement**: Use `#import "YourProjectName-Swift.h"` to access Swift classes in Objective-C.

    **Target Membership**: Ensure your Swift files are added to the correct target.
  </Accordion>

  <Accordion title="Performance Tips" icon="zap">
    **Minimize Bridge Calls**: Create comprehensive wrapper methods rather than making frequent cross-language calls.

    **Error Handling**: Properly handle Swift optionals and errors in your Objective-C code.

    **Threading**: Always dispatch UI updates to the main queue when handling completion callbacks.
  </Accordion>

  <Accordion title="Common Issues" icon="exclamation-triangle">
    **Module Not Found**: Ensure your project's module name doesn't contain special characters or spaces.

    **Swift Version**: Make sure your Objective-C project supports the Swift version used by AmitySDK.

    **Linker Errors**: Verify that both Objective-C and Swift files are properly linked to your target.
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Authentication Guide" icon="shield-check" href="/social-plus-sdk/getting-started/authentication">
    Learn about session management and secure authentication flows
  </Card>

  <Card title="Chat Features" icon="message" href="/social-plus-sdk/chat/overview">
    Start building chat and messaging features
  </Card>

  <Card title="Social Features" icon="users" href="/social-plus-sdk/social/README">
    Add posts, feeds, and social interactions
  </Card>

  <Card title="Video Streaming" icon="video" href="/social-plus-sdk/video-new/broadcasting/overview">
    Implement live video and streaming features
  </Card>
</CardGroup>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Installation Issues" icon="wrench">
    **Framework not found**: Ensure you've added all required frameworks and set them to "Embed & Sign"

    **Swift version conflicts**: Ensure your project uses Swift 5.0 or later
  </Accordion>

  <Accordion title="Runtime Issues" icon="bug">
    **SDK not initialized**: Make sure you call `AmityClient.setup(...)` in `application` delegate

    **Authentication failures**: Verify your API key and region settings

    **Permission denied**: Check that required permissions are added to Info.plist
  </Accordion>

  <Accordion title="Platform-Specific Issues" icon="mobile">
    **M1 Mac Simulator Issues**: Enable Rosetta for your application in Xcode
  </Accordion>
</AccordionGroup>
