# iOS (old)

## Installation

#### Binary vs. Source Code&#x20;

To install Pulse Insights in your application, follow these steps:

1. Add the following line in `Podfile`

```
pod 'PulseInsights'
```

2. Execute the cmd `pod install` to download and set up the SDK
3. Find the generated `.xcworkspace` and open it in Xcode

## Upgrading

To upgrade the library, simply overwrite the .framework package with the newer version.

## Usage

### 1. Initialization

First, configure the shared PulseInsights object inside AppDelegate. You’ll do the following:

* Include the necessary headers.
* Setup the PulseInsights object inside didFinishLaunchingWithOptions.
* Replace YOUR\_ACCOUNT\_ID with your own PulseInsights ID, for example PI-12345678.

First add PulseInsights inside `AppDelegate`:

```
import PulseInsights
```

Then, override the `didFinishLaunchingWithOptions` method:

```
// Optional: set enableDebugMode to true for debug information.

let pi:PulseInsights = PulseInsights(YOUR_ACCOUNT_ID, enableDebugMode:[Bool value])
```

### 2. View tracking <a href="#user-content-2-view-tracking" id="user-content-2-view-tracking"></a>

Pulse Insights allows targeting surveys to a given screen name. In order for the SDK to know the current screen name, you can use the following method to notify it of the current screen name change:

```
PulseInsights.getInstance.setViewName(viewName:String,
controller:UIViewController)
```

For example, you can override the viewDidAppear function on the UIViewController subclass:

```
override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    PulseInsights.getInstance.setViewName("MainView", controller: self)
}
```

### 3. Survey polling <a href="#user-content-3-survey-polling" id="user-content-3-survey-polling"></a>

The Pulse Insights SDK will automatically regularly fetch surveys that would match various targeting conditions, based on a frequency that you can override as shown below:

```
PulseInsights.getInstance.setScanFrequency(setFrequencyInSecond :NSInteger)
```

If you want to manually fetch new surveys, you can also use this method:

```
PulseInsights.getInstance.serve()
```

### 4. Render a specific survey <a href="#user-content-4-render-a-specific-survey" id="user-content-4-render-a-specific-survey"></a>

It is also possible to manually trigger a survey by its id:

```
PulseInsights.getInstance.present(surveyID:String)
```

### 5. Inline surveys <a href="#user-content-5-inline-surveys" id="user-content-5-inline-surveys"></a>

Inline surveys are rendered within the content of the application, instead of overlaying the application content.

In order to integrate inline surveys, you can programmatically create the `InlineSurveyView` object by assigning an identifier and inserting it into a view:

```
var inlineSurveyView:InlineSurveyView?

inlineSurveyView = InlineSurveyView(identifier: String)

self.view.addSubview(inlineSurveyView)
```

If you integrate `InlineSurveyView` with the nib/xib, you can assign the tracking identifier by using the method `setIdentifier`

```
override func viewDidLoad() {
        super.viewDidLoad()
        inlineSurveyView?.setIdentifier(className: String) // assume the inlineSurveyView have been initialized
}
```

Here's another example of assigning the identifier for the inline view from xib

```
@IBOutlet weak var inlineXibView: InlineSurveyView! {
        didSet {
            inlineXibView?.setIdentifier("InlineXib")
        }
    }
```

If you prefer, set up the identifier with the nib layout, as the following screenshot shows. You can find the `Identifier` attribute from the Xcode interface

![](/files/ioCzLxBkAR0lFgPkPKKl)

### 6. Survey rendering

You can pause and resume the survey rendering feature with the following method:

```
PulseInsights.getInstance.switchSurveyScan(boolean enable);
```

And check the current configuration with the following method:

* true: survey rendering feature is enabled
* false: survey rendering feature is paused

```
var renderingConfig: Bool = PulseInsights.getInstance.isSurveyScanWorking();
```

It is also possible to pause the survey rendering from the initialization of the Pulse Insights library as follows:

```
let pi:PulseInsights = PulseInsights(YOUR_ACCOUNT_ID, automaticStart: ${Bool value})
```

### 7. Client Key <a href="#user-content-7-client-key" id="user-content-7-client-key"></a>

Client key can be set using this method:

```
PulseInsights.getInstance.setClientKey(_ clientId: String )
```

The configured client key can be fetched with this method:

```
let getKey: String = PulseInsights.getInstance.getClientKey()
```

### 8. Preview mode <a href="#user-content-8-preview-mode" id="user-content-8-preview-mode"></a>

Preview mode can be enabled/disabled by:

```
Shaking the device more than 10-times in 3-seconds
```

Preview mode can be programmatically enabled or disabled by this method:

```
PulseInsights.getInstance.setPreviewMode(_ enable: Bool)
```

It is also possible to set preview mode from the initialization of the Pulse Insights library:

```
let pi:PulseInsights = PulseInsights(_ accountID:String, enableDebugMode:Bool = false, previewMode:Bool = false)
```

In order to check the status of the preview mode, use this method:

```
let isPreviewModeOn: Bool = PulseInsights.getInstance.isPreviewModeOn()
```

### 9. Callbacks <a href="#user-content-9-callbacks" id="user-content-9-callbacks"></a>

If you want to know if a survey has been answered by the current device, this method can be used:

```
let isSurveyAnswered: Bool = PulseInsights.getInstance.checkSurveyAnswered(_ surveyId: String )
```

It is also possible to configure a callback to be executed when a survey has been answered:

```
class ViewController: UIViewController {
    override func viewDidLoad() {
      super.viewDidLoad()
      PulseInsights.getInstance.setSurveyAnsweredListener(self)
    }

}
extension ViewController: SurveyAnsweredListener {
    func onAnswered(_ answerId: String) {

    }
}
```

### 10. Context data <a href="#user-content-10-context-data" id="user-content-10-context-data"></a>

You can save context data along with the survey results, or for a refined survey targeting, using the `customData` config attribute. For example:

```
let pi:PulseInsights = PulseInsights(YOUR_ACCOUNT_ID, customData: ["gender": "male", "age": "32", "locale": "en-US"])
```

### 11. Device data <a href="#user-content-11-device-data" id="user-content-11-device-data"></a>

If you want to set device data, which will be saved along the survey results, the method `setDeviceData` can be used as follows:

```
PulseInsights.getInstance.setDeviceData(dictData:[String: String]())
```

`setDeviceData` can be called at any time. It will trigger a separate network request to save the data.

### 12. Advanced usage <a href="#user-content-12-advanced-usage" id="user-content-12-advanced-usage"></a>

The default host is "survey.pulseinsights.com". If you want to target the staging environment, or any other environment, it is possible to override the default host:

```
PulseInsights.getInstance.setHost(hostName:String)
```

The debug mode can be turned on and off:

```
PulseInsights.getInstance.setDebugMode(enable:Bool)
```

PulseInsights creates a unique UDID to track a given device. If you wish to reset this UDID, you can call the following method:

```
PulseInsights.getInstance.resetUdid()
```

If you want manually config the view controller, you can call the following method:

```
PulseInsights.getInstance.setViewController(ontroller: UIViewController)
```

And get the view controller object that has been configured.

```
let viewController: UIViewController = PulseInsights.getInstance.getViewController()
```

## Themes <a href="#user-content-uninstall" id="user-content-uninstall"></a>

You can configure approximately 50 properties - such as font color and size - using SDK Themes in the Console:&#x20;

Styling is not driven by CSS but uses native components and formatting instead.

To create a mobile app-compatible theme in the Pulse Insights Console:&#x20;

1. Click the Settings dropdown menu from the top navigation bar
2. Select "Themes"

<figure><img src="/files/EW1DzI1J9aOtPjQ399Wv" alt="" width="164"><figcaption></figcaption></figure>

3. Click the "New Theme" button
4. Give a name to your theme
5. In the "Type" dropdown menu, select "Native"
6. Input your Native JSON theme into the code box
7. "Update"

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

### Uninstall

1. Remove the following statement from your `Podfile`

```
pod 'PulseInsights'
```

2. Execute `pod install` , so the SDK will be removed


---

# 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.pulseinsights.com/implementing-pulse-insights-dev/implementing-in-native-apps/ios-old.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.
