Search code examples
iosauthenticationhockeyapp

How to get HockeyApp user email/id from within iOS app?


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.


Solution

  • 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];