> This page is for Applications Protection.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.humansecurity.com/llms.txt.

# Enable support for Account Defender

#### v3.0

In order to enable Account Defender, a user ID must be set. You can set it by calling the `PerimeterX/setUserId(userId:forAppId:)` function with a **non** `nil` value. When the current user logout, you should call this function again with `nil`. This will turn off the Account Defender.

```swift
do {
    try PerimeterX.setUserId(userId: "<the current user ID>")
}
catch {
    print("error: \(error)")
}
```

```objectivec
NSError *error = nil;
[PerimeterX setUserIdWithUserId:@"<the current user ID>" forAppId:nil error:&error];
if (error != nil) {
    NSLog(@"error: %@", error);
}
```

In order to tell Account Defender about the user's flow, you should call the `PerimeterX/registerOutgoingUrlRequest(url:forAppId:)` function for each URL request that been send to your server. Notice that when the `PXPolicy/urlRequestInterceptionType` is set to any value rather than `PXPolicyUrlRequestInterceptionType/none`, the SDK registers URL requests automatically and you don't need to call this function.

```swift
do {
    try PerimeterX.registerOutgoingUrlRequest(url: "<URL>")
}
catch {
    print("error: \(error)")
}
```

```objectivec
NSError *error = nil;
[PerimeterX registerOutgoingUrlRequestWithUrl:@"<URL>" forAppId:nil error:&error]
if (error != nil) {
    NSLog(@"error: %@", error);
}
```

---

You may add additional data using the `PerimeterX/setAdditionalData(parameters:forAppId:)` function.

```swift
do {
    var additionalData = [String: String]()
    additionalData["key1"] = "value1"
    additionalData["key2"] = "value2"
    try PerimeterX.setAdditionalData(parameters: additionalData)
}
catch {
    print("error: \(error)")
}
```

```objectivec
NSDictionary *additionalData = @{@"key1": @"value1", @"key2": @"value2"};
NSError *error = nil;
[PerimeterX setAdditionalDataWithParameters:additionalData forAppId:nil error:&error];
if (error != nil) {
    NSLog(@"error: %@", error);
}
```