iOS integration

This section describes the process of integrating PLuG using the DevRev SDK with your iOS app.

Requirements

  • Xcode 16.0 or higher (latest stable version available on the App Store)
  • Swift 5.9 or later
  • Set the minimum deployment target for your iOS application as iOS 13

Integration

The DevRev SDK can be integrated using either Swift Package Manager (SPM) or CocoaPods.

We recommend integrating the DevRev SDK using SPM.

Swift Package Manager

To integrate the DevRev SDK into your project using SPM:

  1. Open your project in Xcode and navigate to the Add Package Dependency.
  2. Enter the DevRev SDK URL under Enter Package URL:
  3. In the Build Phases section of your app target, locate the Link Binary With Libraries phase and confirm that DevRevSDK is linked. If not, add it by clicking + and selecting DevRevSDK from the list.

Now you should be able to import and use the DevRev SDK in your project.

CocoaPods

To integrate the DevRev SDK using CocoaPods:

  1. Add the following to your Podfile:
    1pod 'DevRevSDK', '~> 1.0.0'
  2. Run pod install in your project directory.

This will install the DevRev SDK in your project, making it ready for use.

Set up the DevRev SDK

  1. Open the DevRev web app at https://app.devrev.ai and go to the Settings page.
  2. Under PLuG settings copy the value under Your unique App ID.
  3. After obtaining the credentials, you can configure the DevRev SDK in your app.

The DevRev SDK must be configured before you can use any of its features.

The SDK will be ready for use once you execute the following configuration method.

1DevRev.configure(appID:)

For example:

1DevRev.configure(appID: "abcdefg12345")
  • UIKit apps

Configure the SDK in the AppDelegate.application(_:didFinishLaunchingWithOptions:) method.

  • SwiftUI apps

Depending on your app’s architecture, configure the SDK at the app’s entry point or initial view.

Identification

To access certain features of the DevRev SDK, user identification is required.

The identification function should be placed appropriately in your app after the user logs in. If you have the user information available at app launch, call the function after the DevRev.configure(appID:) method.

If you haven’t previously identified the user, the DevRev SDK will automatically create an anonymous user for you immediately after the SDK is configured.

The Identity structure allows for custom fields in the user, organization, and account traits. These fields must be configured through the DevRev app before they can be utilized. For more information, refer to Object customization.

You can select from the following methods to identify users within your application:

Anonymous identification

The anonymous identification method allows you to create an anonymous user with an optional user identifier, ensuring that no other data is stored or associated with the user.

1DevRev.identifyAnonymousUser(userID:)

Unverified identification

The unverified identification method identifies users with a unique identifier, but it does not verify their identity with the DevRev backend.

1DevRev.identifyUnverifiedUser(_:)

The function accepts the DevRev.Identity structure, where the user identifier (userId) is the only required property; all other properties are optional.

Update the user

You can update the user’s information using the following method:

1DevRev.updateUser(_:)

This function accepts the DevRev.Identity structure.

The userID property cannot be updated.

The identification functions are asynchronous. Ensure you wrap them in a Task when calling from synchronous contexts.

For example:

1// Identify an anonymous user without a user identifier.
2await DevRev.identifyAnonymousUser()
3
4// Identify an unverified user using their email address as the user identifier.
5await DevRev.identifyUnverifiedUser(Identity(userID: "user@example.org"))
6
7// Update the user's information.
8await DevRev.updateUser(Identity(organizationID: "organization-1337"))

PLuG support chat

UIKit

The support chat feature can be shown as a modal screen from a specific view controller or the top-most one, or can be pushed onto a navigation stack. 

To show the support chat screen in your app, you can use the following overloaded method:

1await DevRev.showSupport(from:isAnimated:)
  • When a UIViewController is passed as the from parameter, the screen is shown modally.

  • When a UINavigationController is passed as the from parameter, the screen is pushed onto the navigation stack.

If you want to display the support chat screen from the top-most view controller, use the following method:

1await DevRev.showSupport(isAnimated:)

For example:

1// Push the support chat screen to a navigation stack.
2await DevRev.showSupport(from: mainNavigationController)
3
4// Show the support chat screen modally from a specific view controller.
5await DevRev.showSupport(from: settingsViewController)
6
7// Show the support chat screen from the top-most view controller, without an animation.
8await DevRev.showSupport(isAnimated: false)

SwiftUI

To display the support chat screen in a SwiftUI app, you can use the following view:

1DevRev.supportView

New conversation closure

You can receive a callback when a new conversation is created by setting the following closure:

1DevRev.conversationCreatedCompletion

This allows your app to access the ID of the newly created conversation.

For example:

1DevRev.conversationCreatedCompletion = { conversationID in
2 print("A new conversation has been created: \(conversationID).")
3}

Analytics

The DevRev SDK allows you to send custom analytic events by using a name and a string dictionary. You can track these events using the following function:

1DevRev.trackEvent(name:properties:)

For example:

1await DevRev.trackEvent(name: "open-message-screen", properties: ["id": "message-1337"])

Session analytics

The DevRev SDK offers session analytics features to help you understand how users interact with your app.

Opting-in or out

Session analytics features are opted-in by default, enabling them from the start. However, you can opt-out using the following method:

1DevRev.stopAllMonitoring()

To opt back in, use the following method:

1DevRev.resumeAllMonitoring()

Session recording

You can enable session recording to capture user interactions with your app.

The session recording feature is opt-in and is enabled by default.

The session recording feature includes the following methods to control the recording:

MethodAction
DevRev.startRecording()Starts the session recording.
DevRev.stopRecording()Ends the session recording and uploads it to the portal.
DevRev.pauseRecording()Pauses the ongoing session recording.
DevRev.resumeRecording()Resumes a paused session recording.

Session properties

You can add custom properties to the session recording to help you understand the context of the session. The properties are defined as a dictionary of string values.

1DevRev.addSessionProperties(_:)

To clear the session properties in scenarios such as user logout or when the session ends, use the following method:

1DevRev.clearSessionProperties()

Masking sensitive data

To protect sensitive data, the DevRev SDK provides an auto-masking feature that masks data before sending to the server. Input views such as text fields, text views, and web views are automatically masked.

While the auto-masking feature may be sufficient for most situations, you can manually mark additional views as sensitive using the following method:

1DevRev.markSensitiveViews(_:)

If any previously masked views need to be unmasked, you can use the following method:

1DevRev.unmarkSensitiveViews(_:)

Timers

The DevRev SDK offers a timer mechanism to measure the time spent on specific tasks, allowing you to track events such as response time, loading time, or any other duration-based metrics.

The mechanism utilizes balanced start and stop methods, both of which accept a timer name and an optional dictionary of properties.

To start a timer, use the following method:

1DevRev.startTimer(_:properties:)

To stop a timer, use the following method:

1DevRev.stopTimer(_:properties:)

For example:

1DevRev.startTimer("response-time", properties: ["id": "task-1337"])
2
3// Perform the task that you want to measure.
4
5DevRev.stopTimer("response-time", properties: ["id": "task-1337"])

Screen tracking

The DevRev SDK offers automatic screen tracking to help you understand how users navigate through your app. Although view controllers are automatically tracked, you can manually track screens using the following method:

1DevRev.trackScreenName(_:)

For example:

1DevRev.trackScreenName("profile-screen")

Push notifications

You can configure your app to receive push notifications from the DevRev SDK. The SDK is designed to handle push notifications and execute actions based on the notification’s content.

The DevRev backend sends push notifications to your app to alert users about new messages in the PLuG support chat.

Configuration

To receive push notifications, you need to configure your DevRev organization by following the instructions in the push notifications section.

You need to ensure that your iOS app is configured to receive push notifications. You can follow the Apple documentation for guidance on registering your app with Apple Push Notification Service (APNs).

Register for push notifications

Push notifications require SDK configuration and user identification, whether unverified or anonymous, to ensure delivery to the correct user.

The DevRev SDK offers a method to register your device for receiving push notifications. You can register for push notifications using the following method:

1DevRev.registerDeviceToken(_:deviceID:)

The method requires a device identifier, which can either be an identifier unique to your system or the Apple-provided Vendor Identifier (IDFV). Typically, the token registration is called from the AppDelegate.application(_:didRegisterForRemoteNotificationsWithDeviceToken:) method.

For example:

1func application(
2 _ application: UIApplication,
3 didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
4) {
5 guard
6 let deviceID = UIDevice.current.identifierForVendor?.uuidString
7 else {
8 return
9 }
10
11 Task {
12 await DevRev.registerDeviceToken(
13 deviceToken,
14 deviceID: deviceID
15 )
16 }
17}

Unregister from push notifications

If your app no longer needs to receive push notifications, you can unregister the device.

Use the following method to unregister the device:

1DevRev.unregisterDevice(_:)

This method requires the device identifier, which should be the same as the one used during registration. It is recommended to place this method after calling UIApplication.unregisterForRemoteNotifications() in your app.

For example:

1UIApplication.shared.unregisterForRemoteNotifications()
2
3Task {
4 guard
5 let deviceID = UIDevice.current.identifierForVendor?.uuidString
6 else {
7 return
8 }
9
10 await DevRev.unregisterDevice(deviceID)
11}

Handle push notifications

To properly handle push notifications, implement the following method, typically in either the UNUserNotificationCenterDelegate.userNotificationCenter(_:didReceive:) or UIApplicationDelegate.application(_:didReceiveRemoteNotification:fetchCompletionHandler:):

1DevRev.processPushNotification(_:)

For example:

1func userNotificationCenter(
2 _ center: UNUserNotificationCenter,
3 didReceive response: UNNotificationResponse
4) async {
5 await DevRev.processPushNotification(response.notification.request.content.userInfo)
6}

Troubleshooting

  • Issue: Can’t import the SDK into my app.
    Solution: Double-check the setup process and ensure that DevRevSDK is correctly linked to your application.

  • Issue: How does the DevRev SDK handle errors?
    Solution: The DevRev SDK reports all errors in the console using Apple’s Unified Logging System. Look for error messages in the subsystem ai.devrev.sdk.

  • Issue: Support chat won’t show.
    Solution: Ensure you have correctly called one of the identification methods: DevRev.identifyUnverifiedUser(...) or DevRev.identifyAnonymousUser(...).

  • Issue: Not receiving push notifications.
    Solution: Ensure that your app is configured to receive push notifications and that your device is registered with the DevRev SDK.