Integrate PLuG with your iOS app
This guide will help you to integrate PLuG using DevRev SDK with your iOS app.
Requirements
- The latest stable Xcode version, 14.0 or higher, available on the App Store
- Swift 5.7 or later
- Set the minimum deployment target for your iOS application as iOS 15
Setup
Integrating DevRev SDK using Swift Package Manager (SPM).
- Launch Xcode and open your existing project.
- Go to the menu bar and select File > Swift Packages > Add Package Dependency.
- In the Add Package Dependency window, enter the
https://github.com/devrev/devrev-sdk-ios
URL in the Enter Package URL field. - Click the Add Package button to fetch the DevRev SDK package.
- After successfully adding the package, navigate to the Build Phases tab of your app target.
- Confirm that the
DevRevSDK
is listed in the Link Binary With Libraries phase. If not, add it by clicking the + button and selecting DevRevSDK from the list. - Now that the SDK is integrated, you can import and use it in your Swift code.
Setting up the DevRev SDK
Obtain credentials
-
To use the DevRev SDK, you must obtain credentials from the DevRev app Settings pages. Go to Settings > Support > PLuG Tokens through the settings icon in the top-left corner.
-
Under the App Credentials section, generate the necessary credentials for SDK usage. Remember to save both the App ID and App Secret as they are required in the SDK configuration.
-
Acquire the Your Unique App ID (referred to as
supportID
in the code) by visiting the PLuG Settings page.
Initialization
After obtaining the necessary credentials, proceed to configure the DevRev SDK within your application.
- Initialization of the SDK is accomplished by invoking the configuration method:
For example:
- For UIKit apps, configure the SDK within the
AppDelegate.application(_:didFinishLaunchingWithOptions:)
method. - For SwiftUI apps, depending on your app’s architecture, perform SDK configuration either at the entry point or in the initial view of the app.
User identification
To use specific SDK features, user identification is mandatory. Follow these steps to ensure proper user identification when using the DevRev SDK:
-
Utilize the
DevRev.identify(_:)
function for user identification. The function accepts theDevRev.Identification
structure, with only user ID (userID
) as a required property. All other properties are optional.The
DevRev.identify(_:)
function is an asynchronous one ensure that you wrap it in aTask
when calling it from a synchronous context.
For example:
- Place the identification function appropriately in your app, preferably after the user logs in. If user information is available at app launch, invoke the function following the
DevRev.configure(appID:secret:supportID:)
method.
PLuG support chat
UIKit:
The support chat feature in UIKit can be displayed either as a modal screen or pushed onto a navigation stack.
To show the support screen, use the overloaded method:
-
If a
UIViewController
is provided as thefrom
parameter, the screen is presented modally. -
If a
UINavigationController
is provided as thefrom
parameter, the screen is pushed onto the navigation stack.
For example:
SwiftUI:
For SwiftUI apps, a dedicated view is provided. Use the public view property:
New conversation callback:
For convenience, a callback closure is added, so the host app can access the conversation ID.
For example:
Analytics
The DevRev SDK supports sending custom analytic events using a name and a string dictionary. To track these events, use the following function:
For example:
Sample app
The repository includes a sample app showcasing use cases for both UIKit and SwiftUI.
Before using the sample app, follow these steps to configure it with your Apple Developer team and DevRev credentials. For your convenience, the code is marked with compiler error directives (#error) at places that need attention.
- Add your credentials to either
ContentView.swift
(SwiftUI) orAppDelegate.swift
(UIKit). - Remove or comment out the compiler error lines in the respective files.
- Configure code signing for the sample target:
a. Open the project settings.
b. Select the appropriate target.
c. Navigate to the Signing & Capabilities tab.
d. From the Team drop-down, select your development team.
Troubleshooting
-
Issue: Can’t import the SDK into my app.
Solution: Double-check the setup process and ensure thatDevRevSDK
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 subsystemai.devrev.sdk
. -
Issue: Support chat won’t show.
Solution: Verify that you have called the identification method (DevRev.identify(...)
) correctly.