+ Start a Discussion
SoleesSolees 

iOS - how can i open in a WebView a Salesforce page

Hi there i was wondering in iOS on how can i open in a WebView a Salesforce page (Accounts page for example) once i've got the OAuth in my application.  How can i use the user credentials to do this?

 

thanks

Best Answer chosen by Admin (Salesforce Developers) 
SoleesSolees

I've finally got it, everything is in the scopes.  Thanks for the help !!!!

All Answers

J2theCJ2theC

When you authenticate, you receive an authentication token. Use this token to pass to the header of a NSURLRequest (with the url of the page of your choice). 

SoleesSolees

Thanks J2theC, do you know with wich name is the authentication token saved in the salesforce iOS demo ? and by any chance do you have a code example of the solution that you are telling me?

 

regards

Kevin HawkinsKevin Hawkins

Is this an application you're building with the Salesforce Mobile SDK?  There are sample apps for both native and hybrid apps in the iOS repository, that demonstrate how to authenticate with OAuth, and use those credentials to connect to different Salesforce endpoints, including web pages.

SoleesSolees

I cant see where is the sample code of this, do you have the url?

 

thanks a lot

Kevin HawkinsKevin Hawkins

I just realized that some of the details are abstracted away from the direct code in our hybrid sample apps, into the SalesforceHybridSDK.  In the SalesforceHybridSDK project (located at [SalesforceMobileSDK-iOS root]/hybrid/SalesforceHybridSDK/SalesforceHybridSDK.xcodeproj]), take a look at SalesforceHybridSDK/Plugins/SFOAuthPlugin/SalesforceOAuthPlugin.m.  Specifically, take a look at the loggedIn method.  This is where we take the access (session) token retrieved from the OAuth process and apply it to the UIWebView of the hybrid app, as a SID cookie on the web view.  You could use this approach if you wanted to add a web view to your native app, and it would have an authenticated session to Salesforce.

 

If you're actually building a hybrid app, it's easiest to leave those details to the framework, and leverage the SalesforceOAuthPlugin functionality to manage authentication in your app.  You can look at bootstrap.html in [SalesforceMobileSDK-iOS root]/hybrid/SampleApps/VFConnector to see how it uses the OAuth plugin to authenticate the user for the app.

 

Cheers,

Kevin

 

SoleesSolees

I've finally got it, everything is in the scopes.  Thanks for the help !!!!

This was selected as the best answer