Getting Started in Mobile Development with iOS

The Salesforce Mobile SDK for iOS is an open-source toolkit that provides a collection of native Objective-C libraries and Xcode templates to enable developers to rapidly build iOS applications that securely connect to the Salesforce Platform. The SDK abstracts the underlying OAuth 2.0 and REST API calls that are needed to connect an iOS application with the Salesforce Platform, allowing developers to focus on their app's functionality.

The SDK also provides a hybrid container based on the open source Apache Cordova (PhoneGap) project that enables HTML5-based applications to leverage device features like the camera and microphone. The hybrid SDK extends the core Cordova platform to provide additional libraries for key enterprise requirements such as OAuth 2.0 authentication and secure offline storage, effectively providing an enterprise-ready hybrid application container.

Select Architecture

Choose Native to develop iOS applications using Objective-C, and get the ability to access all of the rich features and hardware on the device. Choose Hybrid to convert a web application developed using HTML5, JavaScript and CSS3 into a native iOS binary. A hybrid approach combines the portability of HTML5 with access to device features like the camera and microphone.

Getting Started with iOS Native

This quick start creates a native iOS mobile application using the Salesforce Mobile SDK. Using this app, users can view a list of User records from Salesforce.

Prerequisites

  1. XCode—4.5 is the minimum, but we recommend the latest version. For important information on using various versions of XCode, see this Readme.
  2. iOS 6.0 or higher.
  3. Mac OS X “Lion” or higher.
  4. Node.js.
  5. Sign up for a free Salesforce Platform Developer Edition (DE), if you don’t already have one. This will act as your own personal test environment. You should not use this tutorial with a trial, sandbox, or production org.

Create a Connected App in Salesforce

  1. Log into your Developer Edition.
  2. Open the Setup menu by clicking [Your Name] > Setup.
  3. Create a new Connected App by going to App Setup > Create > Apps.
  4. Click the ‘New’ button in the Connected Apps list.
  5. Fill out all required fields and click ‘Save’:
    1. Connected App: MySampleApp
    2. Developer Name: MySampleApp
    3. Contact Email: Your email
    4. Callback URL: sfdc://success.
    5. Selected all available OAuth scopes
  6. From the detail page of the connect app you just created, copy the Consumer Key and Callback URL as you’ll need these later.

Install the Mobile SDK for iOS

For the fastest, easiest route to iOS development, install Node.js and NPM. Then use NPM to install the forceios package. This package installs the Salesforce Mobile SDK for iOS.

  1. Download Node.js from www.nodejs.org/download.
  2. Run the downloaded installer and accept all prompts asking for permissions to install.
  3. Open a command prompt and type npm and press ENTER to make sure your installation was successful. If you don’t see a page of usage information, revisit the previous step to find out what’s missing.
  4. Install the Mobile SDK: sudo npm install forceios -g
Note: The NPM utility installs the package under /usr/local/lib/node_modules, and links binary modules in /usr/local/bin. Most users need the sudo option because they lack read-write permissions in /usr/local. The -g option allows you to run npm from any directory.

Create a Native iOS App

It's easy to create a new app by entering information on the command line.

  1. On the command line, enter forceios and you'll see a list of options.
  2. Now enter forceios create and enter the appropriate information for each prompt.

Note that you can also enter the app options right on the command line:

forceios create --apptype="native" --appname="package-test" --companyid="com.acme.mobile_apps"
--organization="Acme Widgets, Inc." --outputdir="PackageTest" --packagename="com.test.my_new_app"

Run the Project Template App

After the app creation script finishes, you can open and run the project in Xcode.

  1. Select File > Open, navigate to the output folder you specified, and open your app’s xcodeproj file.
  2. Press Command-R and the default template app runs in the simulator.
  3. On startup, the application starts the OAuth authentication flow, which results in an authentication page. Enter your credentials, and click Login.
  4. Tap Allow when asked for permission

You should now be able to compile and run the sample app. The app logs you into a Salesforce org and issues a SELECT Name FROM User LIMIT 10 query. The result is displayed in a UITableView.

Next Steps

  1. Watch this Dreamforce 2012 session recording on developing offline-capable hybrid and native apps with the Salesforce Mobile SDK and SmartStore.
  2. Learn how to add Push Notifications to your iOS native app using Urban Airship.

Getting Started with iOS Hybrid

This quick start creates a hybrid iOS mobile application using the Salesforce Mobile SDK. A hybrid mobile architecture converts a web application developed using HTML5, JavaScript and CSS3 into a native iOS binary. A hybrid approach combines the portability of HTML5 with access to device features like the camera and microphone.

Using this app, users can view a list of Account and Contact records from Salesforce as well as a list of local device contacts.

Prerequisites

  1. XCode—4.5 is the minimum, but we recommend the latest version. For important information on using various versions of XCode, see this Readme.
  2. iOS 6.0 or higher.
  3. Mac OS X “Lion” or higher.
  4. Node.js.
  5. Sign up for a free Salesforce Platform Developer Edition (DE), if you don’t already have one. This will act as your own personal test environment. You should not use this tutorial with a trial, sandbox, or production org.

Create a Connected App in Salesforce

  1. Log into your Developer Edition.
  2. Open the Setup menu by clicking [Your Name] > Setup.
  3. Create a new Connected App by going to App Setup > Create > Apps.
  4. Click the ‘New’ button in the Connected Apps list.
  5. Fill out all required fields and click ‘Save’:
    1. Connected App: MySampleApp
    2. Developer Name: MySampleApp
    3. Contact Email: Your email
    4. Callback URL: sfdc://success.
    5. Selected all available OAuth scopes
  6. From the detail page of the connect app you just created, copy the Consumer Key and Callback URL as you’ll need these later.

Install the Mobile SDK for iOS

For the fastest, easiest route to iOS development, install Node.js and NPM. Then use NPM to install the forceios package. This package installs the Salesforce Mobile SDK for iOS.

  1. Download Node.js from www.nodejs.org/download.
  2. Run the downloaded installer and accept all prompts asking for permissions to install.
  3. Open a command prompt and type npm and press ENTER to make sure your installation was successful. If you don’t see a page of usage information, revisit the previous step to find out what’s missing.
  4. Install the Mobile SDK: sudo npm install forceios -g
Note: The NPM utility installs the package under /usr/local/lib/node_modules, and links binary modules in /usr/local/bin. Most users need the sudo option because they lack read-write permissions in /usr/local. The -g option allows you to run npm from any directory.

Create a Hybrid iOS App

It's easy to create a new app by entering information on the command line.

  1. On the command line, enter forceios and you'll see a list of options.
  2. Now enter forceios create and enter the appropriate information for each prompt.

When specifying the apptype, use -—apptype=”hybrid_local” for a hybrid app with all code in the local project (your HTML and JavaScript files go in ${target.dir}/assets/www/). Use -—apptype=”hybrid_remote” for a hybrid app with code in a Visualforce app on the server.

Note that you can also enter the app options right on the command line:

forceios create --apptype="hybrid_local" --appname="package-test" --companyid="com.acme.mobile_apps"
--organization="Acme Widgets, Inc." --outputdir="PackageTest" --packagename="com.test.my_new_app"

Run the Project Template App

After the app creation script finishes, you can open and run the project in Xcode.

  1. Select File > Open, navigate to the output folder you specified, and open your app’s xcodeproj file.
  2. Press Command-R and the default template app runs in the simulator.
  3. On startup, the application starts the OAuth authentication flow, which results in an authentication page. Enter your credentials, and click Login.
  4. Tap Allow when asked for permission
  5. Tap to retrieve Contact and Account records from your Developer org.

    Log in

  6. Notice you can also retrieve contacts from the device, something an HTML5 app wouldn't be able to do.

    Log in

Next Steps

  1. Take a deeper dive into creating hybrid applications using the Salesforce Mobile SDK.
  2. Learn best practices for using Apache Cordova (PhoneGap) in a Visualforce page.
  3. Learn how to take a Picture and capture a signature in a hybrid app using the Salesforce Mobile SDK.
  4. Learn how to add geolocation and QR/Bar code scanning to a hybrid app using the Salesforce Mobile SDK.
  5. Watch this Dreamforce 2012 session recording on developing offline-capable hybrid and native apps with the Salesforce Mobile SDK and SmartStore.
  6. Learn how to add voice recognition to a hybrid app using the Salesforce Mobile SDK and the AT&T Toolkit for Salesforce Platform.