API reference
extensionVersion
The extensionVersion() API returns the version of the Profile extension.
Android Java
data-slots=heading, code
data-repeat=2
Syntax
@NonNull public static String extensionVersion()
Example
String extensionVersion = UserProfile.extensionVersion();
Android Kotlin
data-slots=heading, code
data-repeat=1
Example
val extensionVersion = UserProfile.extensionVersion();
iOS Swift
data-slots=heading, code
data-repeat=2
Syntax
static var extensionVersion: String
Example
let extensionVersion = UserProfile.extensionVersion
iOS Objective-C
data-slots=heading, code
data-repeat=2
Syntax
+ (nonnull NSString*) extensionVersion;
Example
NSString *extensionVersion = [AEPMobileUserProfile extensionVersion];
getUserAttributes
The getUserAttributes() API gets the user profile attributes with the given keys.
Android Java
-
callback is invoked after the customer attributes are available.
-
A retail application wants to get the
itemsAddedToCartuser data when processing checkout. WhenAdobeCallbackWithErroris provided, if the operation times out (5s) or an unexpected error occurs, thefailmethod is called with the appropriateAdobeError.
data-slots=heading, code
data-repeat=2
Syntax
public static void getUserAttributes(@NonNull final List<String> keys, @NonNull final AdobeCallback<Map<String, Object>> callback)
Example
UserProfile.getUserAttributes(Arrays.asList("itemsAddedToCart"), new AdobeCallbackWithError<Map<String, Object>>() {
@Override
public void fail(AdobeError adobeError) {
// your customized code
}
@Override
public void call(Map<String, Object> stringObjectMap) {
// your customized code
}
});
Android Kotlin
A retail application wants to get the itemsAddedToCart user data when processing checkout.
When AdobeCallbackWithError is provided, if the operation times out (5s) or an unexpected error occurs, the fail method is called with the appropriate AdobeError.
data-slots=heading, code
data-repeat=1
Example
UserProfile.getUserAttributes(listOf("itemsAddedToCart")) {
object : AdobeCallbackWithError<Map<String, Any?>> {
override fun fail(adobeError: AdobeError) {
// your customized code
}
override fun call(value: Map<String, Any?>) {
// your customized code
}
}
}
iOS Swift
- completion is the callback
functionwhich will be called with user attributes. - A retail application wants to get the
itemsAddedToCartuser data when processing checkout. When the callback is provided, if the operation times out (5s) or an unexpected error occurs, thecompletionmethod is called with the appropriateAEPError.
data-slots=heading, code
data-repeat=2
Syntax
static func getUserAttributes(attributeNames: [String], completion: @escaping ([String: Any]?, AEPError) -> Void)
Example
UserProfile.getUserAttributes(attributeNames: ["itemsAddedToCart"]) { attributes, error in
// your customized code
}
iOS Objective-C
data-slots=heading, code
data-repeat=2
Syntax
+ (void)getUserAttributesWithAttributeNames:(NSArray<NSString *> * _Nonnull) comletion:^(NSDictionary<NSString *,id> * _Nullable, enum AEPError)
Example
NSArray *attributes = @[@"itemsAddedToCart"];
[AEPMobileUserProfile getUserAttributesWithAttributeNames:attributes completion:^(NSDictionary<NSString *,id> * _Nullable, enum AEPError) {
// your customized code
}];
registerExtension
data-variant=warning
data-slots=text1, text2
MobileCore.registerExtensions() API instead.Registers the Profile extension with the Mobile Core extension.
Android Java
data-slots=heading, code
data-repeat=2
Syntax
@Deprecated
public static void registerExtension()
Example
import com.adobe.marketing.mobile.UserProfile
...
UserProfile.registerExtension();
removeUserAttribute
data-variant=warning
data-slots=text1, text2
removeUserAttributes API instead.Deprecated as of 2.0.0. Please use the removeUserAttributes API instead.
Android Java
A retail application wants to remove the itemsAddedToCart user data after the product is purchased.
data-slots=heading, code
data-repeat=2
Syntax
@Deprecated
public static void removeUserAttribute(@NonNull final String attributeName)
Example
UserProfile.removeUserAttribute("itemsAddedToCart");
removeUserAttributes
Removes the user profile attributes for the given keys.
Android Java
You want to remove username, usertype user data when session timeout occurs.
data-slots=heading, code
data-repeat=2
Syntax
public static void removeUserAttributes(@NonNull final List<String> attributeNames)
Example
UserProfile.removeUserAttributes(Arrays.asList("username", "usertype"));
Android Kotlin
You want to remove username, usertype user data when session timeout occurs.
data-slots=heading, code
data-repeat=1
Example
UserProfile.removeUserAttributes(listOf("username", "usertype"))
iOS Swift
You want to remove username, usertype user data when session timeout occurs.
data-slots=heading, code
data-repeat=2
Syntax
public static void removeUserAttributes(List<String> attributeNames)
Example
UserProfile.removeUserAttributes(Arrays.asList("username", "usertype"));
iOS Objective-C
data-slots=heading, code
data-repeat=2
Syntax
+ (void) removeUserAttributesWithAttributeNames:(NSArray<NSString *> * _Nonnull)
Example
[AEPMobileUserProfile removeUserAttributesWithAttributeNames:@[@"username", @"usertype"]]
updateUserAttribute
data-variant=warning
data-slots=text1, text2
updateUserAttributes API instead.Sets the user profile attributes key and value and allows you to create or update a user profile attribute.
Remember the following information:
- If the attribute does not exist, it will be created.
- If the attribute exists, the value will be updated.
- A null attribute value removes the attribute.
Android Java
You want to update username of a user obtained in the log in page:
data-slots=heading, code
data-repeat=2
Syntax
@Deprecated
public static void updateUserAttribute(@NonNull final String attributeName, @Nullable final Object attributeValue)
Example
UserProfile.updateUserAttribute("username", "Will Smith");
updateUserAttributes
Sets the user profile attributes key and value.
Allows you to create/update a batch of user profile attributes:
- String, Integer, Boolean, Double, Array, Map are valid type of user profile attributes.
- Custom objects cannot be saved as a
UserProfileattribute. - If the attribute does not exist, it is created.
- If the attribute already exists, the value is updated.
- A null attribute value will remove the attribute.
Android Java
You want to update username, usertype of a user obtained in the log in page:
data-slots=heading, code
data-repeat=2
Syntax
public static void updateUserAttributes(@NonNull final Map<String, Object> attributeMap)
Example
HashMap<String, Object> profileMap = new HashMap<>();
profileMap.put("username","Will Smith");
profileMap.put("usertype","Actor");
UserProfile.updateUserAttributes(profileMap);
Android Kotlin
You want to update username, usertype of a user obtained in the log in page:
data-slots=heading, code
data-repeat=1
Example
val profileMap = mapOf(
"username" to "Will Smith",
"usertype" to "Actor"
)
UserProfile.updateUserAttributes(profileMap)
iOS Swift
You want to update username, usertype of a user obtained in the log in page:
data-slots=heading, code
data-repeat=2
Syntax
public static func updateUserAttributes(attributeDict: [String: Any])
Example
var profileMap = [AnyHashable: Any]()
profileMap["username"] = "will_smith"
profileMap["usertype"] = "Actor"
UserProfile.updateUserAttributes(attributeDict: profileMap)
iOS Objective-C
data-slots=heading, code
data-repeat=2
Syntax
+ (void)updateUserAttributesWithAttributeDict:(NSDictionary<NSString *,id> * _Nonnull)
Example
NSMutableDictionary *profileMap = [NSMutableDictionary dictionary];
[profileMap setObject:@"username" forKey:@"will_smith"];
[profileMap setObject:@"usertype" forKey:@"Actor"];
[AEPMobileUserProfile updateUserAttributesWithAttributeDict:profileMap];