function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gaurav ThakurGaurav Thakur 

Modifying endpoint URL using Settings, like Salesforce 1 iOS Native app Login Screen

I am creating the iOS Native app in which I am customizing the Login page to look like Salesforce1 iOS app page. It also includes a Settings button which allows user to switch to a different endpoint URL using a dropdown.

I was successful in creating a cutomized page, loading the Login screen and authenticating the user.
 
My problem is that when I switch the endpoint URL to say Sandbox(by default the app is pointing to Production), using the Settings dropdown using the below code.
[[SFUserAccountManager sharedInstance] setLoginHost:loginHost];
and reload the UIWebView Login page again using the below code, it does not set the endpoint that I had selected from the dropdown.
SFAuthenticationViewHandler *authHandler = [[SFAuthenticationViewHandler alloc]
                                                initWithDisplayBlock:^(SFAuthenticationManager *authManager, UIWebView *authWebView) {
                                                    //authController is the custom ViewContoller which has the UIWebView and in this block I am asigning the webview recevied from the SFDC SDK.
                                                    authController.authViewCompleted = NO;
                                                    authController.authWebView = authWebView;
                                                    authWebView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
                                                    authWebView.frame = authController.webViewHolder.bounds;
                                                    [rootViewController presentViewController:authController animated:TRUE completion:nil];
                                                } dismissBlock:^(SFAuthenticationManager *authViewManager) {
                                                    authController.authViewCompleted = TRUE;
                                                    [authController dismissViewControllerAnimated:TRUE completion:nil];
                                                }];
    
    _notificationNameDictionary = @{kSFUserLogoutNotification : kPSSUserLogoutNotification,
                                    kSFUserLoggedInNotification : kPSSUserLoggedInNotification,
                                    kSFLoginHostChangedNotification : kPSSLoginHostChangedNotification};
    
    self.authManager.authViewHandler = authHandler;
    [self.authManager loginWithCompletion:completionBlock failure:failureBlock];

I know for sure that the Sandbox endpoint is set, because when I kill the app and reopen it then the Login Page is loading the Sandbox login page.

I want to know how would I be able to replicate the Settings behavior to take the Sandbox endpoint at runtime, and not the Production endpoint(default one) without letting the user to kill the application.







 
Gaurav KheterpalGaurav Kheterpal
Are you trying this with the latest version (3.1) (https://github.com/forcedotcom/SalesforceMobileSDK-iOS)of the Mobile SDK? The question is for a native app but I've done essentially the same thing in a hybrid app and it worked well for me.

If my answer helps resolve your query, please select it as a 'Best Answer' so that it benefits others and helps us improve the overall quality of the forums.
 
Nimit Hingu 1Nimit Hingu 1
I have done the same and I am facing the same issues I am using the latest version of SDK.
supriya vajjhalasupriya vajjhala
I am facing the same issue. It is observed that on changing loginhost and printing credentials,comsole shows that, domain and redirecturi is still the old setting.
 I have solved it by accessing credentials property like below 
if([SFAuthenticationManager sharedManager].coordinator){
        [SFAuthenticationManager sharedManager].coordinator.credentials.domain = @"test.salesforce.com";
        [SFAuthenticationManager sharedManager].coordinator.credentials.redirectUri = @"https://test.salesforce.com/services/oauth2/success";
}