Build a Hello World App for iOS

Learning Objectives

After completing this unit, you’ll be able to:
  • Embed the Snap-ins SDK frameworks into your iOS project.
  • Wire up some basic Snap-ins SDK features to your iOS project.
  • Describe where to find more Snap-ins resources.

Get Started with iOS

OK. So you’re convinced that the Snap-ins SDK is right for you. You’re excited about how this SDK can wire up some awesome Service Cloud features to your app. You’ve already prepared your org for use with the SDK. In this unit, we show you how quickly you can get this stuff working inside your existing iOS app for iPhone and iPad.

Note

Note

This unit assumes that you’re familiar with iOS development. We’re not going to teach you how to use Swift or how to get around the Xcode IDE. If you’re not familiar with these things, you can still scan the unit to get a feel for what it entails to use this SDK.

Create a Basic Project in Xcode

Now you’re ready to build a simple project. Start off by launching Xcode and creating a Single View Application. Use Xcode 8 or later.

Single View Application

For this example, let’s keep things savvy and use the Swift language.

Swift language

Next, download the Snap-ins iOS SDK from the Service Cloud Snap-ins for Mobile Apps product page. You can find it in the iOS SDK section.

Unzip the SDK and embed all the included framework files into your project.

Embed frameworks

If you prefer to use CocoaPods to install the SDK, or you want to know exactly which frameworks are required for your use case, check out the SDK installation instructions (see Resources).

One more bit of housekeeping before we can add our pretty button. We need to create an App Transport Security (ATS) exception for localhost to serve cached knowledge base articles. Open your project’s Info.plist file and add the following content.

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>localhost</key>
    <dict>
      <key>NSExceptionAllowsInsecureHTTPLoads</key>
      <true/>
    </dict>
  </dict>
</dict>

Add a Help Button

Let’s add a help button to your main view controller.

Drag a button onto your view controller. Rename the button to something helpful, like: Snap-ins Rock!.

Snap-ins Rock!

Align the button to the other views so that it’s positioned correctly on all supported devices.

Now create an action method for the button in our view controller and name it buttonTapped.

Button action step 1

Button action step 2

Button action step 3

Wire Up Your Button

OK. Now let’s get to the coding! We’re going to hook into the Knowledge feature, but you can try any of the other features if you prefer.

First off, open your AppDelegate class and import the frameworks we need:

import ServiceCore
import ServiceKnowledge

Configure your SDK in the application(_:didFinishLaunchingWithOptions:) method:

// Create configuration object with init params
let config = SCSServiceConfiguration(
               community: URL(string: "https://mycommunity.example.com")!,
               dataCategoryGroup: "Regions",
               rootDataCategory: "All")

// Pass configuration to shared instance
ServiceCloud.shared().serviceConfiguration = config

Be sure to replace the placeholder values with real values for your community URL, data category group, and root data category. If you don’t, your app will be very sad when it doesn’t find any Knowledge content. For more detailed guidance, check out Cloud Setup for Knowledge in the Resources section.

So now let’s mosey on down to the ViewController class and make that button do more than just look pretty.

We need to import our frameworks in this file as well.

import ServiceCore
import ServiceKnowledge

Next, let’s launch the Knowledge interface right from that button handler we created earlier using the setInterfaceVisible method.

@IBAction func buttonTapped(_ sender: AnyObject) {
  ServiceCloud.shared().knowledge.setInterfaceVisible(true, 
                                  animated: true,
                                  completion: nil)
}

And that’s that. Launch the app, tap our new button, and bask in your Knowledge glory.

Knowledge on iOS

Pretty cool, huh? From here, you can do all kinds of other things. You can add hero images for any categories or articles. You can rebrand the colors, along with UI text, fonts, and images that are used throughout the interface. Rest assured, working with Case Management, Live Agent Chat, and SOS is just as easy as working with Knowledge.

What’s Next?

What’s that you say? How do you get more info?

Well, you can start with the Snap-ins Developer’s Guide for iOS. It contains more tutorials, more examples, and covers loads more topics. It gives you the info on all the four major feature areas: Knowledge, Case Management, Live Agent Chat, and SOS. You can also refer to the Reference Documentation for iOS for those nitty-gritty details about the API. Find links to these and other great tools in the Resource section.

Next we tackle how to create a similar app for Android.

retargeting