DevRev SDK, used for integrating DevRev services into your iOS app.
- DevRev SDK for iOS
- 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 15
The DevRev SDK can be integrated using either Swift Package Manager (SPM) or CocoaPods.
Caution
We recommend integrating the DevRev SDK using Swift Package Manager. CocoaPods is in maintenance mode since August 2024 and will be deprecated in the future.
You can integrate the DevRev SDK in your project as a Swift Package Manager (SPM) package.
To integrate the DevRev SDK into your project using SPM:
- Open your project in Xcode and navigate to the Add Package Dependency.
- Enter the DevRev SDK URL under Enter Package URL:
- For HTTPS: https://github.com/devrev/devrev-sdk-ios
- For SSH:
[email protected]:devrev/devrev-sdk-ios.git
- 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 selectingDevRevSDK
from the list.
Now you should be able to import and use the DevRev SDK in your project.
To integrate the DevRev SDK using CocoaPods:
- Add the following to your Podfile:
pod 'DevRevSDK', '~> 1.0.0'
- Run
pod install
in your project directory.
This will install the DevRev SDK in your project, making it ready for use.
- Open the DevRev web app at https://app.devrev.ai and go to the Settings page.
- Under PLuG settings copy the value under Your unique App ID.
- After obtaining the credentials, you can configure the DevRev SDK in your app.
The SDK will be ready for use once you execute the following configuration method.
DevRev.configure(appID:)
For example:
DevRev.configure(appID: "abcdefg12345")
Configure the SDK in the AppDelegate.application(_:didFinishLaunchingWithOptions:)
method.
Depending on your app's architecture, configure the SDK at the app's entry point or initial view.
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.
Important
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.
Important
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.
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.
DevRev.identifyAnonymousUser(userID:)
The unverified identification method identifies users with a unique identifier, but it does not verify their identity with the DevRev backend.
DevRev.identifyUnverifiedUser(_:)
The function accepts the DevRev.Identity
structure, with the user identifier (userID
) as the only required property, all other properties are optional.
The verified identification method is used to identify the user with a unique identifier and verify the user's identity with the DevRev backend.
DevRev.identifyVerifiedUser(_:sessionToken:)
You can update the user's information using the following method:
DevRev.updateUser(_:)
The function accepts the DevRev.Identity
structure.
Important
The userID
property can not be updated.
Note
The identification functions are asynchronous, make sure that you wrap them in a Task
when calling them from synchronous contexts.
// Identify an anonymous user without a user identifier.
await DevRev.identifyAnonymousUser()
// Identify an unverified user using their email address as the user identifier.
await DevRev.identifyUnverifiedUser(Identity(userID: "[email protected]"))
// Identify a verified user using their email address as the user identifier.
await DevRev.identifyVerifiedUser("[email protected]", sessionToken: "bar-1337")
// Update the user's information.
await DevRev.updateUser(Identity(organizationID: "foo-bar-1337"))
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:
await DevRev.showSupport(from:isAnimated:)
- When a
UIViewController
is passed as thefrom
parameter, the screen is shown modally. - When a
UINavigationController
is passed as thefrom
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:
await DevRev.showSupport(isAnimated:)
/// Push the support chat screen to a navigation stack.
await DevRev.showSupport(from: mainNavigationController)
/// Show the support chat screen modally from a specific view controller.
await DevRev.showSupport(from: settingsViewController)
/// Show the support chat screen from the top-most view controller, without an animation.
await DevRev.showSupport(isAnimated: false)
To display the support chat screen in a SwiftUI app, you can use the following view:
DevRev.supportView
You have the ability to create a new conversation from within your app. The method will show the support chat screen and create a new conversation at the same time.
DevRev.createSupportConversation()
You can receive a callback when a new conversation is created by setting the following closure:
DevRev.conversationCreatedCompletion
This allows your app to access the ID of the newly created conversation.
DevRev.conversationCreatedCompletion = { conversationID in
print("A new conversation has been created: \(conversationID).")
}
The DevRev SDK provides a mechanism to handle links opened from within any screen that is part of the DevRev SDK.
You can fully customize the link handling behavior by setting the specialized in-app link handler. That way you can decide what should happen when a link is opened from within the app.
DevRev.inAppLinkHandler: ((URL) -> Void)?
You can further customize the behavior by setting the shouldDismissModalsOnOpenLink
boolean flag. This flag controls whether the DevRev SDK should dismiss the top-most modal screen when a link is opened.
DevRev.shouldDismissModalsOnOpenLink: Bool
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:
DevRev.trackEvent(name:properties:)
await DevRev.trackEvent(name: "open-message-screen", properties: ["id": "foo-bar-1337"])
The DevRev SDK provides observability features to help you understand how your users are interacting with your app.
Session analytics features are opted-in by default, enabling them from the start. However, you can opt-out using the following method:
DevRev.stopAllMonitoring()
To opt back in, use the following method:
DevRev.resumeAllMonitoring()
You can enable session recording to capture user interactions with your app.
Caution
The session recording feature is opt-out and is enabled by default.
The session recording feature includes the following methods to control the recording:
Method | Action |
---|---|
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. |
DevRev.processAllOnDemandSessions() |
Stops the ongoing user recording and sends all on-demand sessions along with the current recording. |
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.
DevRev.addSessionProperties(_:)
To clear the session properties in scenarios such as user logout or when the session ends, use the following method:
DevRev.clearSessionProperties()
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:
DevRev.markSensitiveViews(_:)
If any previously masked views need to be unmasked, you can use the following method:
DevRev.unmarkSensitiveViews(_:)
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 works using balanced start and stop methods that both accept a timer name and an optional dictionary of properties.
To start a timer, use the following method:
DevRev.startTimer(_:properties:)
To stop a timer, use the following method:
DevRev.stopTimer(_:properties:)
DevRev.startTimer("response-time", properties: ["id": "foo-bar-1337"])
// Perform the task that you want to measure.
DevRev.stopTimer("response-time", properties: ["id": "foo-bar-1337"])
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:
DevRev.trackScreenName(_:)
DevRev.trackScreenName("profile-screen")
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 notify users about new messages in the PLuG support chat.
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).
Important
Push notifications require that the SDK has been configured and the user has been identified (unverified and anonymous users). The user identification is required to send the push notification 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:
DevRev.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.
func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
guard
let deviceID = UIDevice.current.identifierForVendor?.uuidString
else {
return
}
Task {
await DevRev.registerDeviceToken(
deviceToken,
deviceID: deviceID
)
}
}
If your app no longer needs to receive push notifications, you can unregister the device.
Use the following method to unregister the device:
DevRev.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.
UIApplication.shared.unregisterForRemoteNotifications()
Task {
guard
let deviceID = UIDevice.current.identifierForVendor?.uuidString
else {
return
}
await DevRev.unregisterDevice(deviceID)
}
To properly handle push notifications, implement the following method, typically in either the UNUserNotificationCenterDelegate.userNotificationCenter(_:didReceive:)
or UIApplicationDelegate.application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
:
DevRev.processPushNotification(_:)
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse
) async {
await DevRev.processPushNotification(response.notification.request.content.userInfo)
}
A sample app with use cases for both UIKit and SwiftUI has been provided as part of this repository.
Before you start using the sample app you will need to configure it to be used with your Apple Developer team and your DevRev credentials. For your convenience the code has been marked with compiler error directives (#error
) at the places that need attention.
- Add your credentials to
ContentView.swift
(SwiftUI) orAppDelegate.swift
(UIKit).- After you have added the credentials, delete or comment out the compiler error lines in the respective files.
- Configure the code signing for the sample target:
- Open the project settings (1),
- Select the appropriate target (2),
- Go to the Signing & Capabilities section (3), and
- Select your development team under Team (4).
-
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(...)
,DevRev.identifyVerifiedUser(...)
, orDevRev.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.