# SDK - Offerwall

## Offerwall Integration

> **Prerequisite:** Complete the [SDK Installation](/ios/install-sdk.md) first.

The Offerwall displays a full-screen WebView with all available campaigns. The SDK manages the entire UI — you just present it.

### 1. Display the Offerwall

The SDK ships `MCWebViewController`, a `UIViewController` subclass you can push onto a `UINavigationController` (UIKit) or wrap with `UIViewControllerRepresentable` (SwiftUI).

{% tabs %}
{% tab title="SwiftUI" %}
First, wrap `MCWebViewController` so SwiftUI can host it:

```swift
import SwiftUI
import MyChipsSdk

// Definition of the WebViewWrapper struct.
// UIViewControllerRepresentable allows integrating a UIViewController into a SwiftUI interface.
struct WebViewWrapper: UIViewControllerRepresentable {

    // Property for the ad unit identifier, passed during initialization.
    let adunitId: String
    
    // Access to the SwiftUI environment to manage presentation mode.
    // @Environment provides access to shared values throughout the app.
    @Environment(\.presentationMode) var presentationMode

   // Creates and configures the UIViewController (required by UIViewControllerRepresentable).
    func makeUIViewController(context: Context) -> UINavigationController {
        // Initialize the custom MCWebViewController with the adunitId.
        let webVC = MCWebViewController(
            adunitId: adunitId,
            // Closure defining the behavior when the webViewController is closed.
            // This dismisses the view controller using presentationMode.
            onClose: {
                presentationMode.wrappedValue.dismiss()
            }
        )
        
        // Wrap the webViewController inside a UINavigationController.
        // This allows navigation functionality if required.
        return UINavigationController(rootViewController: webVC)
    }

    // Method to update the existing UIViewController with new data (required by UIViewControllerRepresentable).
    // Not implemented here as no updates are needed for this functionality.
    func updateUIViewController(_ uiViewController: UINavigationController, context: Context) {}
}
```

Then use it inside a `NavigationStack` / `NavigationView`:

```swift
// Definition of the WebViewPage struct, which conforms to the View protocol.
// This struct represents a SwiftUI view that embeds the WebViewWrapper.
struct ContentView: View {
    // The body property defines the content and layout of the view.
    var body: some View {
        NavigationStack {
            // Adding a NavigationLink that navigates to WebView when tapped.
            NavigationLink("Open Offerwall") {
                // Embedding the WebViewWrapper inside the view.
                // The WebViewWrapper takes an adunitId as a parameter.
                WebViewWrapper(adunitId: "AD_UNIT_ID")
                    // Hides the back button in the navigation bar for this view.
                    .navigationBarBackButtonHidden()
            }
        }
    }
}
```

{% endtab %}

{% tab title="UIKit" %}

```swift
import UIKit
import MyChipsSdk

class MainViewController: UIViewController {
    @objc func showOfferwall() {
        let webVC = MCWebViewController(adunitId: "AD_UNIT_ID") { [weak self] in
            self?.navigationController?.popViewController(animated: true)
        }
        navigationController?.pushViewController(webVC, animated: true)
    }
}
```

**That's it.** If you want to open the offerwall on a button press, you can just add a button and invoke the `showOfferwall` method:

```swift
override func loadView() {
    // Create a new UIView instance
    let view = UIView()
    view.backgroundColor = .white // Set background color
    
    // Create and configure the button
    let nextButton = UIButton(type: .system)
    nextButton.setTitle("Show Offerwall", for: .normal)
    nextButton.addTarget(self, action: #selector(showOfferwall), for: .touchUpInside)
    nextButton.translatesAutoresizingMaskIntoConstraints = false // Disable default autoresizing mask
    
    // Add the button to the view
    view.addSubview(nextButton)
    
    // Add constraints for button
    NSLayoutConstraint.activate([
        nextButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
        nextButton.centerYAnchor.constraint(equalTo: view.centerYAnchor)
    ])
    
    // Set the view of the view controller
    self.view = view
}
```

{% endtab %}
{% endtabs %}

> Replace `AD_UNIT_ID` with your Ad unit ID from the [Developer Portal](https://dashboard.maf.ad/).

### **2. (Optional) Customize Toolbar Title**

```swift
MCOfferwallSDK.shared.setToolbarTitle("My Rewards")
```

If no title is set, the toolbar remains blank.


---

# Agent Instructions: 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:

```
GET https://docs.mychips.io/ios/sdk-offerwall.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
