If you have played around with the mobile SDK template for iOS, you may have noticed that the generated app uses a pretty standard single view, more suited for displaying on an iPhone rather than an iPad. Like any good designer, I wanted to make the most of the real estate offered for an iPad app, and use a split-view controller to display my data. However,I want to still leverage the Mobile SDK’s OAuth support to authenticate against Force.com and Database.com. Here’s how.

Start by creating a new project in XCode by using the Master-Detail Application template. Then follow the steps described in the Using the SDK in an existing project of the Getting Started guide to prep your app with the required libraries. With the dependencies and setup out of the way, replace the AppDelegate.m and AppDelegate.h with the following code. (Note, this assumes you are using the default MasterViewController and DetailViewController classes as generated by the Master-Detail template).

There is a lot of code below, but the real key is the setupAuthorizingViewController and loggedIn methods of AppDelegate.m class. It is here that we are setting up the login view where you enter your username and password to start the OAuth flow, and when logged in, switch the view back to our split-view.

AppDelegate.h

AppDelegate.m

Get the latest Salesforce Developer blog posts and podcast episodes via Slack or RSS.

Add to Slack Subscribe to RSS