0
votes

I need to integrate Salesforce iOS native library in my iOS native application and I have to show salesforce login screen and flow as mentioned below:

  1. I have a HOME screen in my iOS native application.
  2. From there I have to navigate to Salesforce login screen.
  3. User will enter credentials and Salesforce will validate it.
  4. Once logged in success then it will back to my HOME screen with token/sessionID.
  5. That token/sessionID I will use internally in my application.

To achieve this I have integrated "SalesforceMobileSDK-iOS-Distribution" from below link https://github.com/forcedotcom/SalesforceMobileSDK-iOS-Distribution in my application. But exactly I don't know from where to and how to start? which class will give me login screen of Salesforce. I tried something like

[SFUserAccountManager sharedInstance].oauthClientId = strClientID;
[SFUserAccountManager sharedInstance].oauthCompletionUrl = strCallbackURI; 
[SFUserAccountManager sharedInstance].scopes = [NSSet setWithObjects:@"api",@"web", nil];

and

[SalesforceSDKManager sharedManager].connectedAppId = strClientID;
[SalesforceSDKManager sharedManager].connectedAppCallbackUri = strCallbackURI;   
[SalesforceSDKManager sharedManager].authScopes = @[@"web", @"api"]; 
[[SalesforceSDKManager sharedManager] launch];

I have connected app information such as Client ID, Secret code and Redirect URI. How can I proceed?

If I use zkSforce library from this link https://github.com/superfell/zkSforce Does it achieve my requirement? Please help me. Thanks in advance.

3

3 Answers

1
votes

Finally I achieved it and the good answer for this question is

  1. Download "SalesforceMobileSDK-iOS-Distribution" from below link https://github.com/forcedotcom/SalesforceMobileSDK-iOS-Distribution .
  2. Extract all the "-Release.zip" files and add those to your application.
  3. Set Header Search path for all libraries as "$(SRCROOT)/your app name/your library name" and choose "recursive".
  4. Set Other linker flags such as "-ObjC" and "-all_load".
  5. Import "SFUserAccountManager.h", "SFAuthenticationManager.h" and "SFIdentityData.h" files.
  6. Add below code snippet to your login action

    [SFUserAccountManager sharedInstance].oauthClientId = strClientID;
    
    [SFUserAccountManager sharedInstance].oauthCompletionUrl = strCallbackURI;
    
    // [SFUserAccountManager sharedInstance].scopes = [NSSet setWithObjects:@"web", @"api", nil];
    
    [[SFAuthenticationManager sharedManager] addDelegate:self];
    
    [[SFAuthenticationManager sharedManager]
     loginWithCompletion:(SFOAuthFlowSuccessCallbackBlock)^(SFOAuthInfo *info) {
         NSLog(@"Authentication Done");
    
         SFIdentityData *claims = [SFAuthenticationManager sharedManager].idCoordinator.idData;
         NSLog(@"claims = %@",claims);
    
         NSLog(@"accessToken = %@", [SFAuthenticationManager sharedManager].coordinator.credentials.accessToken);
    
     }
     failure:(SFOAuthFlowFailureCallbackBlock)^(SFOAuthInfo *info, NSError *error) {
         NSLog(@"Authentication Failed");
     // handle error hare.
     }
     ];
    
    #pragma mark - SFAuthenticationManager
    
    - (void)authManager:(SFAuthenticationManager *)manager willDisplayAuthWebView:(UIWebView *)view{
    
     }
    
    - (void)authManagerDidFail:(SFAuthenticationManager *)manager error:(NSError*)error info:(SFOAuthInfo *)info{
    }
    

hope it would helpful to you.

Note: According to me the "Call back URI" should not start with either "http" or "https".

0
votes

Sales force uses oAuth login. The code should do the magic. What is your main problem ? were u not able show the login page after running the above code ?

Other way to check how SFDC iOS SDK works is to install forceios npm package & create a native iOS application from the cmd it provides. [https://www.npmjs.com/package/forceios]

Application created gives you an glimpse on how the SFDC SDK works [login, Fetch Data from SFDC etc.]

0
votes

1) integrate using CocoaPods pod 'SalesforceSDKCore' import <SFAuthenticationManager.h>

2) make sure you properly configure the OAuthRedirect URL

  • yourapp://authdone
  • add this redirect URL in salesforce server config
  • config redirect URL in your Info.plist

3) use Ganesh's code above, employing SFAuthenticationManager with the oauthCompletionUrl set to the OAuthRedirect URL you have configured. The callback will have the entire user object on success.