# iOS SDK Setup

## 1. Requirements

{% hint style="info" %}

#### Can be used with other push solutions!

To use FlareLane with other push solutions, you must follow some additional steps. Refer to [iOS: Disable Swizzling](/guide-for-developers/mobile-sdk-setup/additional-setup/ios-disable-swizzling.md) for details.
{% endhint %}

* [Sign up](https://console.flarelane.com) to FlareLane and create a project

***

## 2. Credentials Setup

Follow this guide below:

* [iOS: APNS Setup](/guide-for-developers/mobile-sdk-setup/additional-setup/ios-apns-setup.md)

***

## 3. Xcode Setup

Go to `Signing & Capabilities` and click `+ Capability` and add `Push Notifications`

<figure><img src="/files/ZJDZA8XKFLU0Iy5bUYiP" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
To support iOS Rich Notifications, you need to add `Notification Service Extension`
{% endhint %}

In Xcode, select `Notification Service Extension` from File > New > Target

<figure><img src="/files/Lg2SmwaOVae8dqeuXZAl" alt=""><figcaption></figcaption></figure>

Enter the Product Name. In this guide, we will define it as `FlareLaneNotificationServiceExtension`.

<figure><img src="/files/dkGhXYl1s4D2NQ2fGcFy" alt=""><figcaption></figcaption></figure>

Set `Minimum Deployments` of the Notification Service Extension Target you just created to be the same as the main app target you are currently using.

<figure><img src="/files/5fHCF3B87TcfpjhtQ73a" alt=""><figcaption></figcaption></figure>

***

## 4. Install SDK using CocoaPods

Add the following code to your `Podfile`

{% tabs %}
{% tab title="Podfile" %}

<pre><code>// Enable the Dynamic Framework
<strong>use_frameworks!
</strong>
target 'YOUR_PROJECT_NAME' do
  // Add the code below
<strong>  pod 'FlareLane', '1.7.4'  
</strong>end

// Add the name of the extension created previously.
// In this guide, FlareLaneNotificationServiceExtension.
<strong>target 'FlareLaneNotificationServiceExtension' do
</strong><strong>  pod 'FlareLane', '1.7.4'
</strong><strong>end
</strong></code></pre>

{% endtab %}
{% endtabs %}

Run `pod install` in the terminal

***

## 5. Initialization

### (5-1. SwiftUI Only)

Since AppDelegate.swift is not created in the SwiftUI project, the file needs to be created first.

Create a new AppDelegate.swift file and add some code to \<YOUR\_PROJECT\_NAME>App.swift file.

{% tabs %}
{% tab title="\<YOUR\_PROJECT\_NAME>App.swift" %}

<pre class="language-swift"><code class="lang-swift">struct &#x3C;YOUR_PROJECT_NAME>App: App {
    // Add the code below
<strong>    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
</strong>}
</code></pre>

{% endtab %}
{% endtabs %}

### 5-2. AppDelegate

{% tabs %}
{% tab title="Switft(AppDelegate.swift)" %}

<pre class="language-swift"><code class="lang-swift">import FlareLane

class AppDelegate: UIResponder, UIApplicationDelegate {
  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {    

    // Add the code below
    // To subscribe later, set the 3rd parameter to false and then run .subscribe() later.
<strong>    FlareLane.initWithLaunchOptions(launchOptions, projectId: "&#x3C;INPUT_YOUR_PROJECT_ID>", requestPermissionOnLaunch: true)
</strong>    
    return true
  }
}
</code></pre>

{% endtab %}

{% tab title="Objective-C(AppDelegate.m)" %}

<pre class="language-objectivec"><code class="lang-objectivec">@import FlareLane

@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

     // Add the code below
     // To subscribe later, set the 3rd parameter to false and then run the .subscribe() later.
<strong>     [FlareLane initWithLaunchOptions:launchOptions projectId:@"INPUT_YOUR_PROJECT_ID", requestPermissionOnLaunch:true];
</strong>}
</code></pre>

{% endtab %}
{% endtabs %}

### 5-3. Notification Service Extension

Run Xcode again and edit the extension's file. Delete the pre-filled codes and only inherit `FlareLaneNotificationServiceExtension`.

{% tabs %}
{% tab title="Swift(NorificationService.swift)" %}

<pre class="language-swift"><code class="lang-swift">
import FlareLane

<strong>class NotificationService: FlareLaneNotificationServiceExtension {
</strong>}
</code></pre>

{% endtab %}

{% tab title="Objective-C(NotificationService.h/.m)" %}

```objectivec

// NotificationService.h
@import FlareLane;

@interface NotificationService : FLNNotificationServiceExtension
@end

// NotificationService.m
#import "NotificationService.h"

@implementation NotificationService
@end
```

{% endtab %}
{% endtabs %}

***

## 6. Test

After completing all the steps, build and run your app. Devices that subscribe to push notifications will be automatically added to FlareLane console's **All Devices**.

Before actual deployment, be sure to verify that the push notifications are being received properly on the device and that the statistics are accurately recorded when the push notifications are clicked.

***

## 7. Identify your user

FlareLane's device is 'anonymous' and you can match the device with your user based on the unique user ID that identifies your user.

{% hint style="info" %}
Setting up [User ID](/data-integration/user-id.md) has many benefits. You can distinguish whether a user has signed-up, and push notifications can be sent based on the User ID.
{% endhint %}

Usually, when a user sign-up or log-in, you should execute `setUserId`.

{% tabs %}
{% tab title="Swift" %}

```swift
FlareLane.setUserId(userId: "USER_ID")
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
[FlareLane setUserIdWithUserId: @"USER_ID"];
```

{% endtab %}
{% endtabs %}

***

## 8. Additional Setup

To use [Journeys](broken://pages/c8d09eecz6Pn5E2pheMD) or [Message Personalization](broken://pages/Z8YOEAwK3zXqYXBmgIAm), integrate custom data via SDK or API:

* [Data Integration](/data-integration.md)

***

## Resources

[Mobile SDK Reference](/guide-for-developers/mobile-sdk-reference.md)


---

# 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://guide.flarelane.com/guide-for-developers/mobile-sdk-setup/ios-sdk-setup.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.
