- Table of contents
- Requirements
- Setup
- Swift Package Manager (Recommended)
- CocoaPods
- Setting up the DevRev SDK
- Features
- Sample app
- Troubleshooting
- Latest stable Xcode from the App Store, 14.0 or later.
- Swift 5.7 or later.
- Minimum deployment target iOS 15.
You can integrate the DevRev SDK in your project as a Swift Package Manager (SPM) package.
Open your project in Xcode, go to the Add Package
screen, add the following URL under Enter Package URL
:
https://github.com/devrev/devrev-sdk-ios
Make sure you link the framework under the Build Phases screen of your app target. Find the Link Binary With Libraries phase and make sure that DevRevSDK is linked there.
Now you should be able to import and use the DevRev SDK.
The DevRev SDK can also be integrated using CocoaPods. Add the following line to your Podfile
:
pod 'DevRevSDK', '~> 0.9.3'
Then run pod install
in your project directory.
-
Open the Settings page.
-
Under the Support section, go to PLuG Tokens.
-
On the PLuG Tokens page, you will be able create your credentials under the App Credentials. These credentials are referred to as
appID
andsecret
in the code.- Create new credentials, if none exist:
- Or maybe reuse any existing ones:
-
Next, you will have to open the PLuG Settings page, and copy the value under Your Unique App ID.
This value is referred to as
supportID
in the code.
Once you have the credentials, you can configure the DevRev SDK in your app. The SDK will be initialized once you have called the configuration method:
DevRev.configure(appID:secret:supportID:)
DevRev.configure(appID: appID, secret: secret, supportID: supportID)
Configure the SDK in the AppDelegate.application(_:didFinishLaunchingWithOptions:)
method.
Depending on the architecture of your app, you will need to configure the SDK at your entry point or initial view of the app.
Certain features of the SDK require a user identification. Make sure that you identify the user using the DevRev.identify(_:)
function.
The function accepts the DevRev.Identification
structure, with the user ID (userID
) as the only required property, all other properties are optional.
Note: The
DevRev.identify(_:)
function is an asynchronous one, make sure that you wrap it in aTask
when calling it from synchronous contexts.
await DevRev.identify(Identification(userID: "[email protected]"))
The identification function should be placed at the appropriate place in your app after you login your user. If you have the user information at app launch, call the function after the DevRev.configure(appID:secret:supportID:)
method.
The support chat feature can be shown as a modal screen or pushed to a navigation stack.
The following overloaded method will show the support screen:
DevRev.showSupport(from:isAnimated:)
- If a
UIViewController
is passed as thefrom
parameter, then the screen will be shown modally. - If a
UINavigationController
is passed as thefrom
parameter, then the screen will be pushed onto the stack.
DevRev.showSupport(from: mainViewController)
For SwiftUI apps we provide a specific view, you just need to use the public view property:
DevRev.supportView
For convenience, a callback closure has been added, that way the host app will be able to access the conversation ID.
DevRev.conversationCreatedCompletion
DevRev.conversationCreatedCompletion = { conversationID in
print("A new conversation has been created: \(conversationID).")
}
The DevRev SDK supports sending custom analytic events using a name and a string dictionary.
You can track them using the following function:
DevRev.trackEvent(name:properties:)
DevRev.trackEvent(name: "open-message-screen", properties: ["id": "foo-bar-1337"])
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).
Check the Setup again and make sure that DevRevSDK is properly linked.
The DevRev SDK outputs all errors in the console using Apple's Unified Logging System under the subsystem ai.devrev.sdk
.
Make sure you have called the identification method (DevRev.identify(...)
) properly.