Set User Identifier
    • 2 Minutes to read
    • Dark
      Light

    Set User Identifier

    • Dark
      Light

    Article summary

    Overview

    The Set User Identifier feature in iOS allows developers to assign a unique identifier to users across devices. This identifier helps maintain consistent user profiles, enable personalized communication and segment users.

    Use Case

    1. Purpose:

      • Link user-specific data, such as preferences or behaviours, across devices.

      • Enable targeted marketing campaigns and personalized notifications.

    2. Benefits:

      • Improve user segmentation and targeting accuracy.

      • Provide a seamless and personalized user experience.

    Implementation Details

    1. Assign a User Identifier: Use the SDK method to set a unique identifier for a user.

      For Objective-C:

      [[Appoxee shared] setDeviceAlias:@"user12345" withCompletionHandler:^(NSError * _Nullable error) {
          if (!error) {
              NSLog(@"User Identifier set successfully.");
          } else {
              NSLog(@"Failed to set User Identifier: %@", error.localizedDescription);
          }
      }];

      For Swift:

      Appoxee.shared()?.setDeviceAlias("user12345") { error in
          if error == nil {
              print("User Identifier set successfully.")
          } else {
              print("Failed to set User Identifier: \(error?.localizedDescription ?? "Unknown error")")
          }
      }
    2. Retrieve the User Identifier: Fetch the currently assigned user identifier.

      For Objective-C:

      [[Appoxee shared] getDeviceAliasWithCompletionHandler:^(NSError * _Nullable error, NSString * _Nullable alias) {
          if (!error) {
              NSLog(@"Retrieved User Identifier: %@", alias);
          } else {
              NSLog(@"Failed to retrieve User Identifier: %@", error.localizedDescription);
          }
      }];

      For Swift:

      Appoxee.shared()?.getDeviceAliasWithCompletionHandler { error, alias in
          if error == nil, let alias = alias {
              print("Retrieved User Identifier: \(alias)")
          } else {
              print("Failed to retrieve User Identifier: \(error?.localizedDescription ?? "Unknown error")")
          }
      }
    3. Remove the User Identifier: Disassociate the user identifier from the device.

      For Objective-C:

      [[Appoxee shared] removeDeviceAliasWithCompletionHandler:^(NSError * _Nullable error) {
          if (!error) {
              NSLog(@"User Identifier removed successfully.");
          } else {
              NSLog(@"Failed to remove User Identifier: %@", error.localizedDescription);
          }
      }];

      For Swift:

      Appoxee.shared()?.removeDeviceAliasWithCompletionHandler { error in
          if error == nil {
              print("User Identifier removed successfully.")
          } else {
              print("Failed to remove User Identifier: \(error?.localizedDescription ?? "Unknown error")")
          }
      }

    Best Practices

    • Use Unique Identifiers: Ensure the identifier is unique for each user to avoid conflicts across devices.

    • Error Handling: Implement robust error handling for all API calls to ensure reliable operation in various network conditions.

    • Privacy Compliance: Ensure that user identifiers comply with privacy regulations (e.g., GDPR) and are managed securely.

    Keep in mind:

    • User identifiers are device-specific but can be used to associate multiple devices to the same user profile.

    • Use meaningful identifiers like email addresses, usernames, or system-generated IDs for better clarity and management.

    • Test all identifier operations (set, retrieve, and remove) under different app states (foreground, background, and terminated) for reliability.


    Was this article helpful?

    What's Next
    ESC

    AI Assistant, facilitating knowledge discovery through conversational intelligence