Skip to main content
Loop SDK Setup (Swift on iOS)
Written by Aniko Villeneuve
Updated over a week ago

About this SDK

Loop Pulse iOS SDK offers a convenient way to launch surveys in your mobile app with custom surveys for the mobile use case, while minimizing the data the user is required to enter. This document explains how to install and configure the Loop SDK for the iPhone.

Setting up an Embedded Feedback Channel

If you haven’t already, go to the Channels page and create an Embedded Channel. Create a new survey or choose an existing survey. This will generate an app ID for your app.

Installing Loop SDK

The Loop iOS SDK will soon be available on CocoaPods. Add the following dependency to your app’s Podfile:

pod 'LoopSDK', '~> 1.0'

We are also working to make our SDK available via Carthage or as a Framework. The Loop iOS SDK requires iOS 10.0 or newer.

In Swift, in every file you use Loop SDK you’ll need to have to following import statement at the beginning of the file:

import Loop

Initializing the SDK

Find the embedded app ID for the Embedded Pulse Channel, and pass it as a parameter to the initialize method, as shown below.

Insert the following code into your AppDelegate’s application didFinishLaunchingWithOptions method:

[Loop initializeWithAppId:@"appId"];
Loop.initialize(appId: "appId")

Setting the Location

Set the location by providing its number (short code) any time before launching the survey ViewController. If the survey ViewController is launched without setting the location, the user will be asked to pick a location before the survey.

[Loop setLocationWithShortCode: @"0000"];
Loop.setLocation(shortCode: "0000")

Providing Contact Information

Some survey responses result in Loop conversations if the customer decides to open a conversation by leaving contact information. You may already have the essential contact information such as the customer name, email address and phone number. You can pass these values to Loop Pulse, so that the customer won’t need to enter them again, if they decide to be contacted.

Create a LoopContact object. All fields are optional.

LoopContact* contact = [LoopContact new]; = @"John Smith"; = @""; = @"+16135551234";
var contact = LoopContact() = "John Smith" = "" = "+16135551234"

Any time before launching the Pulse survey ViewController, set this contact to the Pulse client:

[Loop setContact: contact];

Adding Custom Field Entries

The Loop platform supports custom fields in a variety of types including text, number and date. Custom fields are metadata that are saved when the customer opens a conversation. You can add custom field entries as key-value pairs where the key is the custom field short code.

Create custom field entries:

NSMutableDictionary entries = [NSMutableDictionary new]; [entries setObject: [NSDate date] forKey:@"orderDate"]; [entries setObject: @"1827012" forKey:@"orderId"];
var entries = [String:AnyObject]() entries["orderDate"] = Date() entries["orderId"] = "1827012"

Any time before launching the Pulse survey ViewController, set the entries to the Pulse client:

[Loop setCustomFieldEntries: entries];

Initializing and Displaying the Survey ViewController

You can show the Pulse survey ViewController any time in your application. You can launch the survey when the user agrees to take the survey by tapping on a button.

The survey has web components that need to be loaded, so in order to offer a better experience to the user, before showing the survey ViewController, we recommend calling the preparePulseView() method. You can call this method in the viewDidLoad method of your ViewController.

[Loop preparePulseView];

Then you can call the following method any time to show the Pulse survey ViewController:

[Loop showPulseView];

The survey ViewController will be dismissed when the user completes the survey or taps on the close or system back buttons.

You can also dismiss the Pulse survey ViewController by calling this method:

[Loop hidePulseView];

You can set an event listener to get notified when the Pulse survey ViewController is dismissed for any reason:

NotificationCenter.default.addObserver(self, selector: #selector(onPulseSurveyResult(notification:)), name: Loop.pulseSurveyResultNotification, object: nil) ... func onPulseSurveyResult(notification: NSNotification) {     switch( {         case .complete:             print("The user has completed the survey")         case .dismissed:             print("User dismissed the survey")         case .canceled:             print("Survey was canceled")         default: break     } }

The result notification enum has the following options:

  • .complete: used when the survey is closed upon successful survey completion.

  • .dismissed: used when the user dismissed the survey.

  • .canceled: used when the survey is dismissed by the app, calling hidePulseView.

Before launching the survey, we recommend setting the location and providing contact information (if available), so that Loop is not going to ask for the same data again and let the user complete the survey as fast as possible.

Did this answer your question?