Setting Named Users upon login

This article will show you how to set a Named User upon first app launch or login so you can message individuals by their Named User rather than their Urban Airship Channel ID.

Determine when you want to set the Named User

For the purposes of this guide, we recommend setting a Named User when your user first authenticates, or logs in, to your application. This may be through the use of a username/password system, or an email address log in.

Whichever method you choose, ensure that your app can query for your users username or email address once they have logged in.

Sample workflow:

  1. A user installs your app on their device.
  2. The user opens your app.
  3. The App will prompt user to log in using their username/password combo, or email address.
  4. The user enters in username/password combo.
  5. The user now successfully logged in to your app.

Setting the Named User

Now that your user is logged in, you'll be free to set your users Named User. Query for the username that is logged in, and use the Urban Airship SDK to set the Named User. Your code will look similar to the following:

iOS / ObjC:

/* Your logic for letting the user log in to their account should be here
 In addition, you should be querying the users information to determine what their username is
 at this point.*/
//Wrap this in an If statement
//If user is logged in
[UAirship push].namedUser.identifier = @"NamedUserID";
//After the necessary Named User has been set, update the registration
[[UAirship push] updateRegistration]


iOS / Swift:

/* Your logic for letting the user log in to their account should be here
 In addition, you should be querying the users information to determine what their username is
 at this point.*/
//Wrap this in an If statement
//If user is logged in
UAirship.namedUser().identifier = "NamedUserID"
//After the necessary Named User has been set, update the registration
UAirship.push().updateRegistration()


Android:

/* Your logic for letting the user log in to their account should be here
 In addition, you should be querying the users information to determine what their username is
 at this point.*/
//Wrap this in an If statement
//If user is logged in
UAirship.shared().getPushManager().getNamedUser().setId("NamedUserID");

And that is all you need to do in order to set a Named User upon user app login.

Never store Personally Identifiable Information(PII) about your users in Urban Airship. If you are using an email address for a user, it is recommended that you hash the information such that the users information is obscured. Alternatively, if you have a Profile ID for a user, choose that for the user instead of using their email address.

Related Content: