Install SDK

1. Introduction

This guide provides a comprehensive walkthrough for integrating the MyChips SDK into your iOS application, enabling the display of an engaging offerwall.

2. SDK Integration

In your project in Xcode go to File -> Add Package Dependencies and then add the dependency using the following repo: https://github.com/myappfree/mychips-ios-sdk

Now in your project you can import the SDK:

import MyChipsSdk

3. Initializating the SDK

Before using the sdk or showing the offerwall you must initialize it:

//replace "YOUR_API_KEY"
MCOfferwallSDK.shared.configure(apiKey: apiKey, userId: userId)

3.1 (Optional) Set userId if you have your own unique id

MCOfferwallSDK.shared.setUserId(userId: "YOUR_USER_ID")

Obtain your API key and User ID from Universal Developer Portal

4. Displaying the Offerwall

To display the offerwall we provide you with a UIViewController which you can integrate into UIKit or SwiftUI project.

To show the offerwall you need to provide your AdUnitId and a closure which closes the offerwall.

For SwiftUI first we need to wrap the UIViewController:

// Definition of the WebViewWrapper struct, which conforms to UIViewControllerRepresentable.
// 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
    
    // Method to create and configure the UIViewController (required by UIViewControllerRepresentable).
    func makeUIViewController(context: Context) -> UINavigationController {
        // Initialize the custom MCWebViewController with the adunitId.
        let webViewController = 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: webViewController)
    }
    
    // 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) {
    }
}

Now we use the wrapper in our view. Since in this example we will use it in a NavigationView we hide the default back button since the offerwall provides its own:

// Definition of the WebViewPage struct, which conforms to the View protocol.
// This struct represents a SwiftUI view that embeds the WebViewWrapper.
struct WebViewPage: View {
    
    // The body property defines the content and layout of the view.
    var body: some View {
        // Embedding the WebViewWrapper inside the view.
        // The WebViewWrapper takes an adunitId as a parameter.
        WebViewWrapper(
            adunitId: "YOUR_AD_UNIT_ID" // Placeholder for the ad unit identifier.
        )
        // Hides the back button in the navigation bar for this view.
        .navigationBarBackButtonHidden()
    }
}

Now we can add this page to our NavigationView and show the offerwall on a button press:

// Definition of the ContentView struct, which conforms to the View protocol.
// This struct represents the main entry point for the SwiftUI interface.
struct ContentView: View {
    
    // The body property defines the layout and content of the view.
    var body: some View {
        // Embedding the view inside a NavigationView.
        // NavigationView provides a navigation interface and allows transitioning between views.
        NavigationView {
            // Using a VStack to arrange elements vertically.
            VStack {
                // Adding a NavigationLink that navigates to WebViewPage when tapped.
                NavigationLink(destination: WebViewPage()) {
                    // The label for the NavigationLink, displayed as a button.
                    Text("Open Offerwall")
                }
            }
        }
    }
}

Your Ad unit ID can be found here

Last updated