Skip to content

devrev/devrev-sdk-ios

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Table of contents

Requirements

  • Latest stable Xcode from the App Store, 14.0 or later.
  • Swift 5.7 or later.
  • Minimum deployment target iOS 15.

Setup

Swift Package Manager (Recommended)

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.

CocoaPods

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.

Setting up the DevRev SDK

Step 1: Credentials

  1. Open the Settings page.

  2. Under the Support section, go to PLuG Tokens.

    \

  3. On the PLuG Tokens page, you will be able create your credentials under the App Credentials. These credentials are referred to as appID and secret in the code.

    • Create new credentials, if none exist:
    • Or maybe reuse any existing ones:
  4. 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.


Step 2: Initialization

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:)

Example

DevRev.configure(appID: appID, secret: secret, supportID: supportID)

UIKit apps

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

SwiftUI apps

Depending on the architecture of your app, you will need to configure the SDK at your entry point or initial view of the app.

Features

Identification

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 a Task when calling it from synchronous contexts.

Example

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.

PLuG support chat

UIKit

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:)
  1. If a UIViewController is passed as the from parameter, then the screen will be shown modally.
  2. If a UINavigationController is passed as the from parameter, then the screen will be pushed onto the stack.

Example

DevRev.showSupport(from: mainViewController)

SwiftUI

For SwiftUI apps we provide a specific view, you just need to use the public view property:

DevRev.supportView

New conversation callback

For convenience, a callback closure has been added, that way the host app will be able to access the conversation ID.

DevRev.conversationCreatedCompletion

Example

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

Analytics

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:)

Example

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

Screenshots



Sample app

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.

  1. Add your credentials to ContentView.swift (SwiftUI) or AppDelegate.swift (UIKit).
    • After you have added the credentials, delete or comment out the compiler error lines in the respective files.
  2. 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).

Troubleshooting

Cannot import the SDK into my app

Check the Setup again and make sure that DevRevSDK is properly linked.

How does the DevRev SDK handle errors?

The DevRev SDK outputs all errors in the console using Apple's Unified Logging System under the subsystem ai.devrev.sdk.

Why won't the support chat show?

Make sure you have called the identification method (DevRev.identify(...)) properly.