> For the complete documentation index, see [llms.txt](https://docs.licensespring.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.licensespring.com/sdks/swift-objective-c-sdk/floating-server-v2.md).

# Floating Server V2

### FS2 Floating client – Method Documentation

### `checkConnection() -> Bool`

Checks whether the FS2 server is reachable.

**Description:**\
Attempts to contact the FS2 backend and verifies that the server responds.

**Returns:**

* `true` if the server is reachable
* `false` if the connection fails

**Use case:**\
Call before authentication or license operations to ensure backend availability.

***

### `authenticateUser(user: String, password: String) throws`

Authenticates a user against the FS2 server.

**Parameters:**

* `user` – Username
* `password` – User password

**Throws:**

* Error if authentication fails (invalid credentials, network error, etc.)

**Description:**\
Establishes an authenticated session required for further license operations.

***

### `getAllLicenses() throws -> [License]`

Fetches all licenses available to the authenticated user.

**Returns:**

* Array of `License` objects

**Throws:**

* Error if request fails or user is not authenticated

**Description:**\
Retrieves licenses assigned or accessible to the current user account.

***

### `register(userID: String, licenseId: License) throws -> License`

Registers a license to a specific user.

**Parameters:**

* `userID` – Identifier of the user
* `licenseId` – License to register

**Returns:**

* Updated `License` object (including features and metadata)

**Throws:**

* Error if registration fails

**Description:**\
Associates a license with a user in the system and prepares it for usage.

***

### `syncConsumptions() throws`

Synchronizes consumption data with the FS2 server.

**Throws:**

* Error if synchronization fails

**Description:**\
Uploads local consumption usage to the backend and refreshes state from server.

**Use case:**\
Required when using metered or consumption-based licenses.

***

### `syncFeatureConsumption() throws`

Synchronizes feature-level consumption with the backend.

**Throws:**

* Error if synchronization fails

**Description:**\
Updates feature usage state between client and server.

**Use case:**\
Used when tracking feature-specific consumption metrics.

***

### `registerFloatingFeature(_ feature: Feature) throws`

Registers (acquires) a floating feature.

**Parameters:**

* `feature` – Feature to register

**Throws:**

* Error if acquisition fails

**Description:**\
Locks a floating feature for use by the current user/session.\
Floating features typically have limited concurrent usage.

***

### `releaseFloatingFeature(_ feature: Feature) throws`

Releases a previously registered floating feature.

**Parameters:**

* `feature` – Feature to release

**Throws:**

* Error if release fails

**Description:**\
Unlocks the floating feature and makes it available to other users.

***

### `borrow(userID: String, licenseId: License, until: Date) throws`

Borrows a license until a specified date.

**Parameters:**

* `userID` – Identifier of the user
* `licenseId` – License to borrow
* `until` – Expiration date of the borrow period

**Throws:**

* Error if borrow operation fails

**Description:**\
Marks a license as borrowed for offline use until the given expiration date.

**Use case:**\
Allows temporary offline usage without continuous server connectivity.

Token Handling

Some license operations require an authentication token.

### `getToken() -> JwtToken?`

Retrieves the JWT token from the authenticated FS2 user session.

**Description:**\
Returns the token issued during authentication.\
This token must be passed to license-level operations that communicate with the backend.

**Example:**

```
let token = fs2User.getToken()

try license.fullCheck(env: "mac", token: token)
```

**Note:**\
If the token is `nil`, the user is not authenticated or the session has expired.

***

## License-Level Methods (Token-Based)

These methods are called on a `License` instance and require a valid `JwtToken` for server communication.

***

### `fullCheck(env:isFloatingServerV2:token:)`

```
public func fullCheck(
    env: String? = nil,
    isFloatingServerV2: Bool = false,
    token: JwtToken? = nil
) throws
```

Performs a complete license validation.

**Parameters:**

* `env` – Environment identifier (`"mac"`, `"win"`, `"linux"`, etc.)
* `isFloatingServerV2` – Indicates whether Floating Server V2 logic should be used
* `token` – JWT token obtained from authenticated FS2 user

**Throws:**

* Error if remote validation fails
* Error if local validation fails
* Error if token is missing for required remote validation

**Description:**\
Performs both:

* Local validation (expiry, feature constraints, etc.)
* Remote validation against LicenseSpring platform

**Use case:**\
Call before allowing protected functionality.

***

### `synchronize(env:isFloatingServerV2:token:)`

```
public func synchronize(
    env: String? = nil,
    isFloatingServerV2: Bool = false,
    token: JwtToken? = nil
) throws
```

Fetches fresh license state from the LicenseSpring platform.

**Parameters:**

* `env` – Optional environment identifier
* `isFloatingServerV2` – Floating server version flag
* `token` – JWT token

**Throws:**

* Error if synchronization fails
* Error if token is invalid or missing

**Description:**\
Updates the local license object with the latest server-side data.

**Use case:**\
Call periodically or before critical operations to ensure license state is current.

***

### `syncFeatureConsumption(code:token:)`

```
public func syncFeatureConsumption(
    code: String? = nil,
    token: JwtToken? = nil
) throws
```

Synchronizes consumption data for feature(s).

**Parameters:**

* `code` – Specific feature code to sync. If `nil`, syncs all consumption features.
* `token` – JWT token

**Throws:**

* Error if sync fails
* Error if token is missing

**Description:**\
Uploads local consumption usage for feature-based consumption licenses.

**Note:**\
Only meaningful for **Consumption Features**.

***

### `syncConsumptions(token:)`

```
public func syncConsumptions(
    token: JwtToken? = nil
) throws
```

Synchronizes license-level consumption data with the backend.

**Parameters:**

* `token` – JWT token

**Throws:**

* Error if sync fails

**Description:**\
Updates total consumption state between client and server.

**Note:**\
Only meaningful for **Consumption-based licenses**.

***

### `registerFloatingFeature(_:token:)`

```
public func registerFloatingFeature(
    _ licenseFeature: LicenseFeature,
    token: JwtToken? = nil
) throws
```

Registers (acquires) a floating feature.

**Parameters:**

* `licenseFeature` – Feature to acquire
* `token` – JWT token

**Throws:**

* Error if acquisition fails
* Error if token is missing

**Description:**\
Locks a floating feature for the current user/session.

**Use case:**\
Used in floating license environments where concurrent feature usage is limited.

***

## Token-Based Flow Example

```
try fs2User.authenticateUser(user: username, password: password)

guard let token = fs2User.getToken() else {
    throw SomeError.noToken
}

let license = try fs2User.register(userID: userID, licenseId: licenseId)

try license.fullCheck(env: "mac", token: token)
try license.synchronize(env: "mac", token: token)
try license.syncConsumptions(token: token)
try license.syncFeatureConsumption(token: token)

if let floatingFeature = license.features.first {
    try license.registerFloatingFeature(floatingFeature, token: token)
}
```

***

## Important Notes

* `JwtToken` is required for any license operation that communicates with the backend.
* Token is obtained via authenticated FS2 user session.
* If token expires, re-authentication is required.
* Floating and consumption operations depend on proper token propagation.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.licensespring.com/sdks/swift-objective-c-sdk/floating-server-v2.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
