> For the complete documentation index, see [llms.txt](https://docs.abtasty.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.abtasty.com/server-side/sdks/ios/ios-1/migration-to-4x.md).

# Migration to v4.X

This guide will assist developers to move from Flagship 3.X to Flagship 4.X.

The main breaking changes are:

* Consent Management
* Visitor Status

See the full change log on [Github](https://docs.developers.flagship.io/docs/ios-sdk).

## Consent Management

The version 4.X introduces a required consent parameter when creating a Visitor `instance`:

**`public func newVisitor(visitorId: String, hasConsented: Bool, instanceType: Instance = .SHARED_INSTANCE) -> FSVisitorBuilder`**

```swift

// 1-  In the version 4.X we added a label for visitorId parameter and introduce required consent parameter.
// 2-  Remove from the builder .hasConsented function.
let visitor1 = Flagship.sharedInstance.newVisitor(visitorId:"userId", hasConsented:true)
                        .withContext(context: ["isVip":true])
                        .isAuthenticated(true)
                        .build()
```

```swift
import Flagship

// When omitted default consent value was true.
let visitor1 = Flagship.sharedInstance.newVisitor("visitor_1")
                .withContext(context: ["age" : 32, "isVip":true])
                .isAuthenticated(true)
                .hasConsented(hasConsented: true)
                .build()
```

## Flagship SDK Status

### Status Listener

The `withStatusListener` renamed to [withOnSdkStatusChanged](/server-side/sdks/ios/ios-1/swift-reference.md#getstatus-method)*and the type of parameter from***FStatus***to***FSSdkStatus**\_

* **`func withOnSdkStatusChanged(_ onSdkStatusChanged: @escaping (_ newStatus: FSSdkStatus)->Void)->FSConfigBuilder`**

```swift
func withOnSdkStatusChanged(_ onSdkStatusChanged: @escaping (_ newStatus: FSSdkStatus)->Void)->FSConfigBuilder
```

```swift
public func withStatusListener(_ onStatusChanged: @escaping (_ newStatus: FStatus)->Void)->FSConfigBuilder
```

### Get Status

```swift
// Get the current flagship sdk
public func getStatus() -> FSSdkStatus
```

```swift
// Get the current flagship sdk
public func getStatus() -> FStatus 
```

### Status Values

| Status                      | Description                                                                                                                                                          |
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ***SDK\_NOT\_INITIALIZED*** | The SDK has not been started                                                                                                                                         |
| ***SDK\_INITIALIZING***     | The SDK still starting, in *bucketing mode* the sdk needs to download the ressources (bucketing file) before start. if the file exist already this status is skipped |
| ***SDK\_INITIALIZED***      | The SDK is ready to use.                                                                                                                                             |
| ***SDK\_PANIC***            | The SDK is ready but is running in Panic mode: All visitor's features are disabled except 'fetchFlags' which refreshes this status.                                  |

## Flag

The `defaultValue` in 4.X is provided at the reading [value](/server-side/sdks/ios/ios-1/swift-reference.md#getvalue-method) method through the flag instance and not as 3.X which is provided at `getFlag` method.

### Get Flag

You can retrieve [Flag](/server-side/sdks/ios/ios-1/swift-reference.md#flag-class) by using the following functions from the Visitor instance:

* **`func getFlag(key:String)->FSFlag`**

```swift
import Flagship
// Create visitor "visitor1" and fetch flags
//Get flag for vip feature
let flag = visitor1.getFlag(key:"displayVipFeature")
```

```swift
import Flagship
// Create visitor "visitor1" and fetch flags
// Get flag for vip feature and providing a default value at the flag creation
let flag = visitor1.getFlag(key:"displayVipFeature",defaultValue: false)
```

### Reading Flag Value

To read the current flag's value, simply call `value()` method of the [Flag](/server-side/sdks/ios/ios-1/swift-reference.md#flag-class) object.

* **`func value<T>(defaultValue:T?,visitorExposed: Bool = true)->T?`**

```swift
import Flagship
// Create visitor "visitor1" and fetch flags
//Get flag for vip feature
let flag = visitor1.getFlag(key:"displayVipFeature")
  
// Get value for the flag and provide a default value
let shouldDisplayVipFeature = flag.value(defaultValue: false)
```

```swift
import Flagship
// Create visitor "visitor1" and fetch flags
// Get flag for vip feature and providing a default value at the flag creation
let flag = visitor1.getFlag(key:"displayVipFeature",defaultValue: false)
  
// Get value for the flag
let shouldDisplayVipFeature = flag.value()
```


---

# 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.abtasty.com/server-side/sdks/ios/ios-1/migration-to-4x.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.
