Get Started with Native iOS Development
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.
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.
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”.
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.
- 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 is simple. In a Terminal window, type:
The forceios utility prompts you to enter configuration values for your new project. Use these values:
|Application type||native_swift (or press RETURN) for Swift|
|Organization name||MyApps, Inc.|
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.
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.
- In Xcode, select .
- Navigate to the TrailiOSApps folder and select the MyTrailNativeApp.xcworkspace file. Be sure to open the workspace file rather than the project file.
- Click Open.
- In the Xcode Project Navigator (⌘1), select .
- In the Root node:
- Set RemoteAccessConsumerKey to the consumer key from your connected app.
- Set OAuthRedirectURI to the callback URL from your connected app.
- Select (⌘1).
- Log in with your DE username and password.
- 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.