Start tracking your progress
Trailhead Home
Trailhead Home

Get Started with Native iOS Development

Learning Objectives

After completing this unit, you'll be able to:

  • Describe two primary features of Mobile SDK for iOS.
  • Install Mobile SDK for iOS.
  • Create a native iOS project and specify application options.
  • Run the Xcode project template app.

Native iOS Development

Salesforce Mobile SDK delivers technology and tools for creating native iOS apps that access Salesforce. Mobile SDK simplifies your life as an iOS developer in several ways:

  • It automates the OAuth2 login process, so it’s a snap to integrate login and optional passcodes in your app.
  • You access Salesforce REST APIs through wrapper methods that make SOQL queries, SOSL searches, and CRUD operations a breeze.
  • You can choose to write native iOS apps in either Objective-C or Swift. Swift is the recommended path.

Let’s get going! We assume you’ve already set up your development environment. If you haven’t, make a quick detour to the Set Up Your Mobile SDK Developer Tools project to get everything you need.

Once you’re ready to move forward, you start by creating a simple native iOS Swift app. Later, you modify your app's basic REST request and add functionality to delete records. Finally, you learn how to add Mobile SDK to an existing iOS project with CocoaPods.

iOS Version

This trail module is based on iOS 12.4, the current forceios default version. However, Mobile SDK 8.0 also provides an iOS 13 template that uses SceneDelegate, Combine, and SwiftUI. The iOS 13 template is available in the iOS13NativeSwiftTemplate folder of the SalesforceMobileSDK-Templates GitHub repo.

You can create and explore iOS 13 Mobile SDK apps by running the forceios createwithtemplate command. At the first prompt, enter the name of the template: “iOS13NativeSwiftTemplate”.

Creating a Connected App



The Salesforce Mobile SDK Basics module, which includes connected app instructions, is a prerequisite to this module. You can’t complete this unit's challenge without creating a connected app.

To connect to the Salesforce service, every mobile app requires a Salesforce connected app. A connected app authorizes your app to communicate with Salesforce and securely access Salesforce APIs.

After you create and save your connected app, notice its details.
  • Copy the Callback URL and Consumer Key values. You use these values to set up authentication in your app.
  • Mobile SDK apps do not use the consumer secret, so you can ignore this value.

Creating an iOS Project with Forceios



Although this badge requires forceios, in the real world you have another option! You can also create native iOS apps manually without forceios, npm, or CocoaPods. See “Resources” at the end of this page for a link to manual project instructions.

Creating an iOS project with forceios is simple. In a Terminal window, type:

forceios create

The forceios utility prompts you to enter configuration values for your new project. Use these values:

Configuration setting Value
Application type native_swift (or press RETURN) for Swift
Application name MyTrailNativeApp
Package name com.mytrail.ios
Organization name MyApps, Inc.
Output directory TrailiOSApps

After a sequence of log messages, a congratulatory message appears. Pat yourself on the back, too. Your new native iOS app is now ready to run.

Running Your New iOS App

The project created by forceios is ready to run immediately. It doesn’t do a whole lot—it just executes a simple SOQL query and displays a table of names. But at least you know that the plumbing is in place and ready to do your bidding. Let’s see it in action!

Before posting any Mobile SDK app publicly, remember to replace the generic settings with values from your own connected app. So that you don’t forget, let’s do that now.

  1. In Xcode, select File | Open.
  2. Navigate to the TrailiOSApps folder and select the MyTrailNativeApp.xcworkspace file. Be sure to open the workspace file rather than the project file.
  3. Click Open.
  4. In the Xcode Project Navigator (⌘1), select MyTrailNativeApp | MyTrailNativeApp | Supporting Files | bootconfig.plist.
  5. In the Root node:
    • Set RemoteAccessConsumerKey to the consumer key from your connected app.
    • Set OAuthRedirectURI to the callback URL from your connected app.
  6. Select Product | Run (⌘1).
  7. Log in with your DE username and password.
  8. When prompted, click Allow to let the app access your data in Salesforce. You should see a table listing the names of users defined in your DE org.
List of contacts