iOS Client Development Quick Start

By Oracle Global Pre-sales Consulting

Follow these steps to quickly embed the Oracle Live Experience widget into your iOS app.

Prerequisites

Before continuing, make sure you've met the following prerequisites:

  • Xcode version 10.2 or higher.

  • Swift version 5.0 or higher.

  • The Live Experience iOS SDK downloaded and extracted to a folder on your computer.

  • Credentials (client_id/client_secret) to access a provisioned application on an active Live Experience Tenant account.

  • An Apple device running iOS 10 or above.

  • Some experience with the Swift programming language

Create a New Xcode Project

To make things easier, let's create a new Xcode project from scratch:

  1. Select File then New then Project...

  2. Select Single View App.

  3. Make sure Swift is selected as the development language.

  4. Give your project a name and location and click Create.

    Xcode will start in the Project Navigator with the General tab already open:

  5. Scroll down to the Embedded Binaries section.

  6. Click + and click the Add Other... button.

  7. Find the live-experience-ios-sdk folder you extracted from the iOS SDK zip.

  8. Open the release folder, select all three framework files inside, and click Open.

  9. Make sure Copy items if needed is checked when prompted and click Finish.

  10. Click the Build Settings tab.

  11. Type bitcode into the Search field of the tab.

  12. Change the Enable Bitcode build option from Yes to No.

Next we need to request permission to access the camera and microphone in our app:

  1. On the left pane of the Xcode window is a tree view of the project's files. Click on the Info.plist file and it will appear in the center pane.

  2. Hover your mouse over Information Property List and click the + button and do the following:

    1. Start typing Privacy (with a capital P) and select the option named Privacy - Camera Usage Description.

    2. Set the value of this option to the text you want to show the user when requesting camera access. For example, Can I use your camera?.

  3. Hover your mouse over Information Property List and click the + button and do the following:

    1. Start typing Privacy (with a capital P) and select the option named Privacy - Microphone Usage Description.

    2. Set the value of this option to the text you want to show the user when requesting camera access. For example, Can I use your microphone?.

Authenticate and Add the Live Experience Widget

Now that your Xcode project is prepared, you are ready to authenticate to Live Experience and add the widget to the UI of your iOS app.

  1. On the left pane of the Xcode window is a tree view of the project's files. Click on the ViewController.swift file and it will appear in the center pane.

  2. Look for the line, import UIKit and add import OracleLive below it.

  3. Look for the viewDidLoad() function and paste the following code below the line that says, // Do any additional setup after loading the view, typically from a nib, and replace the following values with your own:

    • client_id: replace with your client ID

    • client_secret: replace with your client secret

    • tenantID: replace with your assigned tenant name

    • userID: replace with your user ID

    // Application credentials from LX console
     
    let client_id = "1fntfqg6k45nh4o8t3rt"
    let client_secret = "379709dd-c230-42d4-9f7a-7564501ccfb9"
    let loginString = String(format: "%@:%@", client_id, client_secret)
    let loginData = loginString.data(using: String.Encoding.utf8)!
    let base64LoginString = loginData.base64EncodedString()
     
    let url = URL(string: "https://live.oraclecloud.com/auth/apps/api/access-token?grant_type=client_credentials&nonce=&state=12345&scope=optional")!
     
    var request = URLRequest(url: url)
     
    // REST call requires Basic Auth
    request.httpMethod = "GET"
    request.setValue("Basic \(base64LoginString)", forHTTPHeaderField: "Authorization")
     
    let task = URLSession.shared.dataTask(with: request) { data, response, error in
      guard let data = data, error == nil else {
        print("XXXXXXXXX URLRequest error: \(error!.localizedDescription)")
        return
      }
     
      if let httpStatus = response as? HTTPURLResponse {
        // Check status code returned by the http server. Should be 200
        print("XXXXXXXXX HTTP status code: \(httpStatus.statusCode)")
     
        // Process result
        do {
          let json = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String:Any]
          if let token = json?["access_token"] as? String {
            Controller.shared.service.authToken = token
     
            // LX Configuration
            Controller.shared.service.tenantID = "Your_Tenant_Name"
            Controller.shared.service.userID = "yourid@example.com"
            Controller.shared.contextAttributes.setValue("Collaboration", forKey: "appLocation")
            // Display the Widget
            Controller.shared.addComponent(viewController: self)
          } else {
            print("XXXXXXXXX Error: \(json?["description"] ?? "Unknown")")
          }
        } catch let error as NSError {
          print("XXXXXXXXX JSON parse errors: \(error)")
        }
      }
    }
    task.resume()
    

    What that code does is authenticate you with Live Experience using your tenant, Your_Tenant_ID which you need to replace with your own tenant name. Once the authentication is successful, the Live Experience mobile component is added to your ViewController and will appear in the bottom right corner of your app.

Test Your App

Go ahead and run your project by clicking the Play button in the Xcode interface. If all went well, your device or simulator will look like this:

Call an Associate

You were sent an Associate account and instructions to install the Live Experience demo app via email. Follow these instructions and make sure your phone. using the Live Experience demo app, and browser can talk to each other.

Things to Try

Now that you have a working iOS app, start experimenting with Live Experience features. Here are some things to try...

Change Camera Settings

Add the following lines to your code to configure camera options (the names should be self-explanatory):

Controller.shared.settings.startVideoInFullScreen = true
Controller.shared.settings.startVideoWithFrontCamera = true

Try Out Different Scenarios

The code above selects the Collaboration scenario. Scenarios control which channels (video, audio, screen share) are available. Replace Collaboration in the code with one of the following to try out other pre-configured scenarios:

  • Basic_Guidance

  • Remote_Support

  • Personal_Shopper

  • Concierge

  • Short_Code

  • Meeting

Add Context Attributes

When you call an associate with your app you'll see Not Available and Unknown User in the engagement information pane. Let's customize and pass that information to the associate using context attributes:

Controller.shared.contextAttributes.setValue("John Smith", forKey: "fullName")
Controller.shared.contextAttributes.setValue("john.smith@ example.com", forKey: "email")
Controller.shared.contextAttributes.setValue("+1-202-555-0171", forKey: "phone")
Controller.shared.contextAttributes.setValue("Redwood City, CA", forKey: "location")

Return to the Docs Home Page

Add Live Experience Features to iOS Apps