iPhone中Salesforce API中的自登录?
我正在使用Salesforce api,我想自动登录(硬代码用户名和密码)。我正在使用REST API,下面是显示登录表单的登录代码:iPhone中Salesforce API中的自登录?,iphone,xcode,login,salesforce,Iphone,Xcode,Login,Salesforce,我正在使用Salesforce api,我想自动登录(硬代码用户名和密码)。我正在使用REST API,下面是显示登录表单的登录代码: - (void)login { SFOAuthCredentials *credentials = [[[SFOAuthCredentials alloc] initWithIdentifier:remoteAccessConsumerKey] autorelease]; credentials.p
- (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];
}
我想要的是,自动登录(而不是询问用户名或密码)以便在哪里插入用户名和密码?Salesforce toolkit for iOS页面显示了一个使用ZKSForce的示例,它返回一个可由REST API调用使用的令牌,请参阅 RESTAPI通常使用OAuth令牌,这样用户就不必在第三方系统(如您的系统)中输入用户名和密码。他们输入一次登录,系统刷新令牌以保持登录(这是一个过于简单的解释)。使用OAuth,这是mobile和REST API的正确方式,或者使用老式SOAP登录请求中的会话ID。
- 在项目中包括zkforce
- 在项目中添加这些文件
- 在.m中添加此代码
- 见结果
快速谷歌一下,我发现了这个-
我还没试过呢 嗨,你成功了吗?感谢您的指导。您是否已完成此操作或需要代码?请提及@Sukithacan,请发布代码片段。谢谢你,请给我你的电子邮件地址,我会发给你的sukie2@gmail.com,提前谢谢。这太好了。您是如何使用SFRestAPI的?@Umar_uas您能告诉我们如何将此代码与Rest Api集成吗?Umair,StackOverflow的目的是让我们都能从其他解决方案中获益。您在发布实际解决方案方面做得很糟糕。您没有给出关于ZKSForce类的链接或说明。请在您的答案中包含更多链接。如果链接中断,答案对任何人都没有帮助:)
#import "ZKSforce.h"
#import "FDCServerSwitchboard.h"
#import "ZKLoginResult.h"
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:)];
- (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.");
}
}