This guide provides a comprehensive walkthrough for integrating the MyChips SDK into your iOS application, enabling the display of an engaging 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.
// below is an example of a view controller which you// can load into your scene and open the offerwall// on a button pressclassFirstViewController:UIViewController {overridefuncloadView() {// Create a new UIView instancelet view =UIView() view.backgroundColor = .white // Set background color// Create and configure the buttonlet 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 }@objcfuncshowOfferwall() {let mcWebView =MCWebViewController( adunitId:"YOUR_AD_UNIT_ID", onClose: { self.navigationController?.popViewController(animated:true) }) self.navigationController?.pushViewController(mcWebView, animated:true) }}
For SwiftUI first we need to wrap the UIViewController:
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:
structWebViewPage:View {var body: some View {WebViewWrapper( adunitId:"YOUR_AD_UNIT_ID"//hide the navigationbarbackbutton since we provide our own).navigationBarBackButtonHidden() }}
Now we can add this page to our NavigationView and show the offerwall on a button press:
structContentView:View {var body: some View {NavigationView {VStack {// Button to navigate to the WebViewPageNavigationLink(destination: WebViewPage(), label: { Text("Open Offerwall") .padding() .background(Color.blue) .foregroundColor(Color.white) .cornerRadius(10) }) } } }}