# ALSDK iOS Framework

This guide explains how to integrate the ALSDK framework into your iOS app. You can choose either manual integration or the Swift Package Manager (SPM) method. For dynamic development and easier updates, we recommend using SPM.

## Prerequisites

* **iOS Deployment Target:** iOS 12 or later
* **Xcode:** Version 11 or higher
* **ALSDK.xcframework:** The prebuilt framework file

## Integration Options

#### Manual Integration

1. **Download the Framework:**
   * Obtain the `ALSDK.xcframework` folder.
2. **Add to Your Xcode Project:**
   * Open your project in Xcode.
   * Drag and drop the `ALSDK.xcframework` folder into your Project Navigator.
     * **Tip:** Check “Copy items if needed” to include a local copy.
3. **Link the Framework:**
   * Select your app target.
   * Go to the **General** tab.
   * Under **Frameworks, Libraries, and Embedded Content**, click the **+** button, select `ALSDK.xcframework`, and add it.
   * Set the embed option to **Embed & Sign** if required.

#### Swift Package Manager Integration

1. In Xcode, open your project and choose **File > Swift Packages > Add Package Dependency…**
2. Enter the package repository URL.
3. Select the desired version (e.g., “Up to Next Major” starting at 1.0.0).
4. Xcode will download and integrate the package automatically.

## Setup

For the SDK to be active, there are 2 key elements to add to your code.

### Framework initialization

* In your AppDelegate, import the framework at the top of the file:

  ```swift
  import ALSDK
  ```
* And in the `didFinishLaunchingWithOptions` method, add the following line of code:

  ```swift
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
          ....
          _ = ALSDKManager.shared // Add this line to init the ALSDK
          ...
          return true
      }
  ```

This is all it takes to have the SDK monitor your app! Now you need to declare the apps you want to detect.

### Crypto App Detection

On iOS, mobile apps can detect the presence of other apps as long as they declare the list of apps prior to packaging the code.

To enable your app to detect the presence of other apps via canOpenURL, you need to declare the URL schemes in your app’s Info.plist using the **LSApplicationQueriesSchemes** key. Here’s how to do it:

1. **Open Info.plist:**\
   In your Xcode project, select your app target and open its Info.plist file.
2. **Add LSApplicationQueriesSchemes:**
   * Right-click in the Info.plist editor and choose **Add Row**.
   * Set the key to **LSApplicationQueriesSchemes** and its type to **Array**.
3. **List the Schemes:**
   * Under the newly added array, add a new item for each URL scheme you want to query.
   * For the list of apps the ALSDK can detect, and their URL schemes, please refer to [this list](broken://spaces/K7kCO4JzdC97BAAQQzEl).
4. **Save Changes:**\
   Save the file, and your app will now be allowed to call `canOpenURL` on the schemes you've listed.

{% hint style="info" %}
Keep the list of apps to detect lean - 5 is a good number to get started. Make sure to mention to Apple during the review process that there schemes are added because you want to provide a seamless experience for your users when they will connect their crypto wallets to your app.
{% endhint %}

## User ID tracking

The SDK allows you to pass it a user ID in order to reconcile visitor context, including wallet presence, and user profile.

To pass a user ID, use the following function on the SDK:

```swift
ALSDK.shared.externalId = 'userid@mail.com' // Should use your internal user ID format
```

## Event tracking

You can post custom events via the SDK, in order for instance to have accurate conversion reporting based on them.

To trigger the tracking of an event, call the `ALSDK.postCustomEvent` function, for instance as follows:

```swift
ALSDK.shared.postCustomEvent("Order Successful", "ORDERID-12345")
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.absolutelabs.io/features/insights/mobile-apps/alsdk-ios-framework.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
