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 MyChipsSdk3. 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)Obtain your API key from Universal Developer Portal
3.1 (Mandatory) Set Identifier for Advertisers
Improve reward tracking and eCPM performance by passing the IDFA.
MCOfferwallSDK.shared.setIdfa(idfa: "YOUR_IDFA")3.2 (Optional) Set userId if you have your own unique id
MCOfferwallSDK.shared.setUserId(userId: "YOUR_USER_ID")Replace
"YOUR_USER_ID"with your actual user ID variable or value.If you do not provide a specific user ID, one will be automatically generated.
3.3 (Optional) Set User Age
You can set the user’s age to help improve ad targeting and analytics.
MCOfferwallSDK.shared.setAge(30);Replace 30 with your actual user age variable or value (integer).
💡 Note:
The value should be an integer (e.g., 18, 25, 30).
Expected range is 0–100 (inclusive).
3.4 (Optional) Set User Gender
You can set the user’s gender to help improve ad targeting and analytics.
MCOfferwallSDK.setGender(.female);Available enum values:
.male
.female
.other3.5 (Optional) Set custom parameters (aff_sub1–aff_sub5 )
aff_sub1–aff_sub5 )MCOfferwallSDK.shared.setAffSub1("YOUR_CUSTOM_VALUE")
MCOfferwallSDK.shared.setAffSub2("YOUR_CUSTOM_VALUE")
MCOfferwallSDK.shared.setAffSub3("YOUR_CUSTOM_VALUE")
MCOfferwallSDK.shared.setAffSub4("YOUR_CUSTOM_VALUE")
MCOfferwallSDK.shared.setAffSub5("YOUR_CUSTOM_VALUE")We provide 5
aff_subparameters (aff_sub1,aff_sub2,aff_sub3,aff_sub4,aff_sub5), which you can use to pass custom values.Replace
"YOUR_CUSTOM_VALUE"with your actual custom value.
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")
}
}
}
}
}
// below is an example of a view controller which you
// can load into your scene and open the offerwall
// on a button press
class FirstViewController: UIViewController {
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
}
@objc func showOfferwall() {
let mcWebView = MCWebViewController(
adunitId: "YOUR_AD_UNIT_ID",
onClose: {
self.navigationController?.popViewController(animated: true)
}
)
self.navigationController?.pushViewController(mcWebView, animated: true)
}
}Your Ad unit ID can be found here
Last updated