# Reward User

#### 1. Fully Managed by MyChips

{% hint style="info" %}
Use this method only if you have selected Self-Managed Currency. If you already support S2S postback please skip this snippet.
{% endhint %}

To check for a reward use the getReward function. It requires your adunitId, a reward callback(which will be called if the checks shows that there is a reward), and an on error callback.

```swift
MCOfferwallSDK.shared.getReward(adunitId: "YOUR_AD_UNIT_ID") { reward in
        //do something with the reward, here we just print it
        print(reward.virtualCurrencyReward)
    } onError: { error in
        //do something with the error, here we just print it
        print(error)
    }

```

> If there is no reward and no error, nothing will happen

You should check for the reward whenever the app is started or resumed. Example integration:

{% tabs %}
{% tab title="SwiftUI" %}

<pre class="language-swift"><code class="lang-swift"><strong>// Import necessary modules for SwiftUI and the custom SDK.
</strong>import SwiftUI
import MyChipsSdk

// Main entry point of the SwiftUI app, marked with @main attribute.
@main
struct MyChipsSdkSwiftUIExampleApp: App {
    
    // Access the current scene phase (e.g., active, inactive, background) using @Environment.
    @Environment(\.scenePhase) var scenePhase
    
    // State variable to track whether the app is being activated for the first time.
    @State private var firstActive = true
    
    // Define the body property, specifying the app's main scene.
    var body: some Scene {
        // The main window group of the app.
        WindowGroup {
            // The root view of the app is ContentView.
            ContentView()
                // Perform actions when the scene phase changes (e.g., active, inactive, background).
                .onChange(of: scenePhase, perform: { phase in
                    // Check if the app is currently active.
                    if phase == .active {
                        // If this is the first activation (app startup):
                        if firstActive {
                            // Initialize the SDK with the API key.
                            MCOfferwallSDK.shared.configure(apiKey: "YOUR_API_KEY")
                            
                            // Optionally set a user ID for tracking or personalization.
                            MCOfferwallSDK.shared.setUserId(userId: "YOUR_USER_ID")
                            
                            // Mark firstActive as false so this block won't execute again.
                            firstActive = false
                        }
                        
                        // Check for any rewards when the app starts or resumes.
                        MCOfferwallSDK.shared.getReward(
                            adunitId: "YOUR_AD_UNIT_ID") { reward in
                                // Handle successful reward retrieval by printing the reward amount.
                                print(reward.virtualCurrencyReward)
                            } onError: { error in
                                // Handle any errors encountered during reward retrieval.
                                print(error)
                            }
                    }
                })
        }
    }
}

</code></pre>

{% endtab %}

{% tab title="UIKit" %}

```swift
class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    var window: UIWindow?
    
    var firstActive = true
    func sceneDidBecomeActive(_ scene: UIScene) {
        if (firstActive) {
            //at the app start initialize the sdk
            let _ = MCOfferwallSDK.shared.configure(apiKey: "YOUR_API_KEY")
            //optionally set user id
            MCOfferwallSDK.shared.setUserId(userId: "YOUR_USER_ID")
            firstActive = false
        }
        
        //other the start or resume check for the reward and do something
        MCOfferwallSDK.shared.getReward(
            adunitId: "YOUR_AD_UNIT_ID") { reward in
                print(reward.virtualCurrencyReward)
            } onError: { error in
                print(error)
            }
    }
    
    //...OTHER SCENEDELEGATE FUNCTIONS

}

```

{% endtab %}
{% endtabs %}

#### 2. Server-to-Server (S2S) Postbacks

If you prefer server-to-server communication, MyChips can send a postback to your server with bonus information. The configuration for postbacks is available in your publisher dashboard. This method is useful for validating and securely rewarding users without client-side manipulation.&#x20;

If you are testing in Sandbox mode, the value of the macro {user\_payout} will be 0.


---

# 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/reward-user.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.
