1

I have my HockeyApp users authenticating with their email address, as described in the HockeyApp documentation.

How can I get the user's email (or ID, or name) from within the app?

There are properties which would seem to hold these values, but they appear to be write-only, and always return as nil: (docs)

[BITHockeyManager sharedHockeyManager].userEmail
[BITHockeyManager sharedHockeyManager].userName
[BITHockeyManager sharedHockeyManager].userID

The header docs say to "see also" this method:

 [BITHockeyManagerDelegate userEmailForHockeyManager:componentManager:]

But I cannot find where to get an object of type BITHockeyBaseManager.

Stan James
  • 2,535
  • 1
  • 28
  • 35
  • Those properties are for setting data that gets attached to crash reports. I don't think you can access the info the user used to authenticate – dan Apr 11 '16 at 18:33
  • @dan Turns out it *is* accessible, as Lukas discovered. Very useful! – Stan James Apr 12 '16 at 22:48

1 Answers1

3

The properties you mentioned above, and alternatively the delegate methods in BITHockeyManagerDelegate are used to enrich crash reports and feedback messages with additional meta data about your user.

The email address that is used during the authentication process is securely saved to the iOS keychain and normally not easily accessible by the app developer.
I stand corrected: Actually, there is a public API for exactly this purpose, [[BITHockeyManager sharedManager].authenticator publicInstallationIdentifier]. Also take a look at the documentation or the actual code.

Example for getting user email anywhere in the app:

NSString *email = BITHockeyManager.sharedHockeyManager.authenticator.publicInstallationIdentifier;

Note that this will return either the user email(kBITAuthenticatorUserEmailKey) or an id code (kBITAuthenticatorIdentifierKey) based on how you set up your authenticator. To set up using email authentication, I used BITAuthenticatorIdentificationTypeHockeyAppEmail. Here is the HockeyApp code in my AppDelegate:

[[BITHockeyManager sharedHockeyManager] configureWithIdentifier:@"<#App id#>" delegate:self];
[[BITHockeyManager sharedHockeyManager].authenticator setAuthenticationSecret:@"<#App Secret#>"];
[[BITHockeyManager sharedHockeyManager].authenticator setIdentificationType:BITAuthenticatorIdentificationTypeHockeyAppEmail];
[[BITHockeyManager sharedHockeyManager] startManager];
[[BITHockeyManager sharedHockeyManager].authenticator authenticateInstallation];
Stan James
  • 2,535
  • 1
  • 28
  • 35
Lukas Spieß
  • 2,478
  • 2
  • 19
  • 24
  • Also: If you need to *reset* the user identifier for HockeyApp, use `[[BITHockeyManager sharedHockeyManager].authenticator cleanupInternalStorage];`, as documented [here](http://hockeyapp.net/help/sdk/ios/3.8.2/Classes/BITAuthenticator.html#//api/name/cleanupInternalStorage). – Stan James Apr 13 '16 at 18:49
  • Correct. Just be aware that the user might then be re-prompted for their authentication credentials. – Lukas Spieß Apr 13 '16 at 19:13