Query for username in Salesforce iOS SDK

前端 未结 5 1237
生来不讨喜
生来不讨喜 2021-01-22 16:27

I have an iOS app using the latest Salesforce iOS SDK. It authenticates users through a webview using oAuth2.0 on the Salesforce site so I do not capture the username in my app

相关标签:
5条回答
  • 2021-01-22 16:35

    FOR SWIFT

    To display full name and chatter profile picture of logged in user in UILabel and UIImageView using Salesforce Mobile SDK 4 you need to first create @IBOutlets

    @IBOutlet weak var yourtextLabel: UILabel!
    @IBOutlet weak var profileImage: UIImageView!
    

    Then all you need is the following in your 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
    
    0 讨论(0)
  • 2021-01-22 16:42

    SalesforceMobileSDK-iOS 7.0

    Swift Version

    import SalesforceSDKCore
    
    guard let userId = UserAccountManager.shared.currentUserAccountIdentity?.userId else {return}
    

    Depends on what you need, this maybe helpful as well:

    guard let userId = UserAccountManager.shared.currentUserAccount?.idData?.userId else {return}
    
    0 讨论(0)
  • 2021-01-22 16:45

    I have no idea whether you use REST or SOAP API...

    For REST there's an excellent article by metadaddy: http://wiki.developerforce.com/page/Digging_Deeper_into_OAuth_2.0_at_Salesforce.com#The_Force.com_Identity_Service

    Identity Service link is in format of /id/(organization id)/(user id), scroll up in this blog post a bit to find out when you should expect it.

    Workbench

    SOAP API, offers getUserInfo() method (it returns an object similar to Apex UserInfo class). Just click the first link there to see the full list of methods you can call.

    0 讨论(0)
  • 2021-01-22 16:49

    You need to import SFAuthenticationManager.h class

    #import <SalesforceSDKCore/SFAuthenticationManager.h>
    

    then you can get user details (first name, last name, email etc.) this way

    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);
    
    0 讨论(0)
  • 2021-01-22 16:51

    username of current user is stored in SFIdentityData object

    #import "SFIdentityData.h"
    
    NSString *userName = [SFAccountManager sharedInstance].idData.username;
    
    0 讨论(0)
提交回复
热议问题