在Salesforce iOS SDK中查询用户名
我有一个使用最新的Salesforce iOS SDK的iOS应用程序。 它使用Salesforce网站上的oAuth2.0通过webviewvalidation用户,所以我不会在我的应用程序中捕获用户名。 有没有办法,我可以查询用户名或者使用API或会话信息? 我只是希望能够显示用户名,以便用户知道他们login了哪个帐户(如果他们有多个)谢谢,约瑟夫
当前用户的用户名存储在SFIdentityData对象中
#import "SFIdentityData.h" NSString *userName = [SFAccountManager sharedInstance].idData.username;
我不知道你是否使用REST或SOAP API …
对于REST , metadaddy提供了一篇优秀的文章: http : //wiki.developerforce.com/page/Digging_Deeper_into_OAuth_2.0_at_Salesforce.com#The_Force.com_Identity_Service
身份服务链接的格式为/id/(organization id)/(user id)
,在这个博客文章中向上滚动一下,找出你应该期望的时间。
SOAP API提供了getUserInfo()
方法(它返回一个类似于Apex UserInfo
类的对象)。 只需点击第一个链接即可查看可以调用的方法的完整列表。
对于SWIFT
要使用Salesforce Mobile SDK 4在UILabel和UIImageView中显示login用户的全名和聊天个人资料图片,您需要先创build@IBOutlets
@IBOutlet weak var yourtextLabel: UILabel! @IBOutlet weak var profileImage: UIImageView!
那么你所需要的就是你的viewDidLoad()
yourtextLabel.text = SFAuthenticationManager.sharedManager().idCoordinator.idData.displayName let imageURL = SFAuthenticationManager.sharedManager().idCoordinator.idData.pictureUrl let image = UIImage(data: NSData(contentsOfURL: imageURL!)!) profileImage.image = image
您需要导入SFAuthenticationManager .h类
#import <SalesforceSDKCore/SFAuthenticationManager.h>
那么你可以通过这种方式获得用户的详细信息( 名字 , 姓氏 , 电子邮件等)
NSLog(@"userData= %@",[SFAuthenticationManager sharedManager].idCoordinator.idData); NSLog(@"first name = %@",[SFAuthenticationManager sharedManager].idCoordinator.idData.firstName); NSLog(@"last name = %@",[SFAuthenticationManager sharedManager].idCoordinator.idData.lastName); NSLog(@"email name = %@",[SFAuthenticationManager sharedManager].idCoordinator.idData.email);