Query for username in Salesforce iOS SDK
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. Is there a way that I can query for the username either using the API or the session information somehow? I just want to be able to display the username so that the user knows which account they have logged into (if they have more than one)
4 Solutions Collect From Internet About “Query for username in Salesforce iOS SDK”
username of current user is stored in SFIdentityData object
#import "SFIdentityData.h" NSString *userName = [SFAccountManager sharedInstance].idData.username;
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.
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.
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
You need to import SFAuthenticationManager.h class
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);
- swift – Convert a String to a Date and then to a String in a different format
- Querying Core Data for Specific Attributes when Creating New Objects and returning the object if it exists, or creating a new one if it does not
- Objective-C category is not loaded – How to debug this
- Error when adding input view to textfield iOS 8
- Adding frameworks to project in Xcode 5 and having *relative* paths added
- iOS Simulator Crash Logs
- NSString stringwithFormat memory leak with ARC
- Xcode not compiling any project? 'clang failed with exit code 255'
- Difference between “+” and “-” before function name in Objective-C
- Swift extension for ?
- How to draw a UILabel with a different blend mode in draw(_ rect: CGRect) in Swift
- UITableView scrolling slow, memory leak issue
- Swipe left or right to load the view controller with the collection view cell highlight
- Display image in notification bar with remote notification(Rich media push notification) in iOS 10
- HTTP Request in Swift with POST method in swift3