在iPhone中的Salesforce API中自我登录? [英] Self login in Salesforce API in iPhone?

查看:109
本文介绍了在iPhone中的Salesforce API中自我登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Salesforce api,我想自动登录(硬编码用户名和密码)。我正在使用REST API,这里是显示登录表单的登录代码:

   - (void)login {
SFOAuthCredentials * credentials = [[[SFOAuthCredentials alloc] initWithIdentifier:remoteAccessConsumerKey] autorelease];
credentials.protocol = @https;
credentials.domain = OAuthLoginDomain;
credentials.redirectUri = OAuthRedirectURI;

self.coordinator = [[[SFOAuthCoordinator alloc] initWithCredentials:credentials] autorelease];
self.coordinator.delegate = self;
NSLog(@%@,self.coordinator);
//如果我们要缓存密钥,请删除此行,并有效地使用刷新流
//,我们说,清除旧登录并每次重新验证
[self。协调员revokeAuthentication];

//现在让我们验证
[self.coordinator authenticate];
}

我想要什么,自动登录(不要求用户名或密码)所以哪里我插入用户名和密码?

解决方案


  • 在项目中包含zkforce

  • 在项目中添加这些文件




  #importZKSforce.h
#importFDCServerSwitchboard.h
#importZKLoginResult.h





  • 在.m中添加此代码



< blockquote>

  NSString * username = 
NSString * password =
NSString * token = @amnwcg24Uu5IenCvAJM5HgRq;
NSString * passwordToken = [NSString stringWithFormat:@%@%@,密码,令牌];
[[FDCServerSwitchboard switchboard] loginWithUsername:username password:passwordToken target:self selector:@selector(loginResult:error :)];





  • 查看结果




   - (void)loginResult:(ZKLoginResult *)结果错误:(NSError) *)错误
{
if(结果&&!错误)
{
NSLog(@嘿,我们登录了!);
// [self fetchAccounts];
}
else if(error)
{
NSLog(@尝试登录时出错。);
}
}



I am using Salesforce api and i want to login automatically(hard code user name and password). i am using REST API and here is the login code which shows login form:

- (void)login {
                SFOAuthCredentials *credentials = [[[SFOAuthCredentials alloc] initWithIdentifier:remoteAccessConsumerKey] autorelease];
                credentials.protocol = @"https";
                credentials.domain = OAuthLoginDomain;
                credentials.redirectUri = OAuthRedirectURI;

                self.coordinator = [[[SFOAuthCoordinator alloc] initWithCredentials:credentials] autorelease];
                self.coordinator.delegate = self;
                NSLog(@"%@",self.coordinator);
                // remove this line if we want to cache the key, and use refresh flow
                //effectively, we are saying, purge the old login and re-authenticate each time
                [self.coordinator revokeAuthentication];

                //now let's authenticate
                [self.coordinator authenticate];
            }

What i want, to automatically login (not ask username or password) so where i insert user name and password?

解决方案

  • Include zkforce in your project
  • Add These files in your project

#import "ZKSforce.h"
#import "FDCServerSwitchboard.h"
#import "ZKLoginResult.h"

  • Add this code in .m

        NSString *username = 
        NSString *password = 
        NSString *token = @"amnwcg24Uu5IenCvAJM5HgRq"; 
        NSString *passwordToken = [NSString stringWithFormat:@"%@%@", password, token];
        [[FDCServerSwitchboard switchboard] loginWithUsername:username      password:passwordToken target:self selector:@selector(loginResult:error:)];

  • See result

- (void)loginResult:(ZKLoginResult *)result error:(NSError *)error
{
    if (result && !error)
    {
        NSLog(@"Hey, we logged in!");
      //[self fetchAccounts];
    }
    else if (error)
    {
        NSLog(@"An error occurred while trying to login.");
    }
}

这篇关于在iPhone中的Salesforce API中自我登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆