This guide provides step-by-step instructions on how to include the Conscent.ai Plugin in your iOS app. The Conscent.ai Plugin is developed in swift Language.
Pre-requisites
Conscent.ai iOS SDK supports iOS 13.0 and above.
Installation Steps
You can download the CCPlugin.xcframework File from here and add it to your project.
Make sure you change the embed mode for CCPlugin.xcframework to "Embed & Sign".
Initialize the SDK
Import the CCPlugin framework into your ViewController class.
importCCPlugin
Configure the SDK in didFinishLaunchingWithOptions in AppDelegate class
funcapplication(_application: UIApplication, didFinishLaunchingWithOptionslaunchOptions: [UIApplication.LaunchOptionsKey:Any]?) ->Bool {// Configure the SDK CCPlugin.shared.configure(mode: .sandbox, clientID:"your-client-id")// Additional configurations if necessaryreturntrue}
yourClientId - Pass your clientId received from Conscent.ai.
Mode - configuration testing of different environments available.
Api Mode can be setas: Mode.sandbox Mode.production
You need to set the scrollDepth for the paywall by accessing the scrollDepth property of the CCPlugin.shared instance and modifying its value.
// Retrieve and set the scroll depthlet screenHeight = scrollView.bounds.heightlet scrollDepth: Int=Int(scrollView.contentOffset.y)CCplugin.shared.scrollDepth = scrollDepth
You have to confirm UIScrollViewDelegate and you need to set scrollDepth and scrollDepthPercentage.
funcscrollViewDidEndDecelerating(_scrollView: UIScrollView) {let scrollDepth: Int=Int(scrollView.contentOffset.y) CCplugin.shared.scrollDepth = scrollDepthlet contentHeight = scrollView.contentSize.heightlet scrollViewHeight = scrollView.bounds.heightlet scrollOffset = scrollView.contentOffset.y// Calculate the scroll percentagelet scrollDepthPercentage = (scrollOffset / (contentHeight - scrollViewHeight)) *100.0// Use the scrollPercentage as needed (e.g., update a label or send to analytics)print("Scroll Depth: \(scrollDepthPercentage)%") CCplugin.shared.scrollDepthPercentage = scrollDepthPercentage }funcscrollViewDidEndDragging(_scrollView: UIScrollView, willDeceleratedecelerate: Bool) {let contentHeight = scrollView.contentSize.heightlet scrollViewHeight = scrollView.bounds.heightlet scrollOffset = scrollView.contentOffset.y// Calculate the scroll percentagelet scrollDepthPercentage = (scrollOffset / (contentHeight - scrollViewHeight)) *100.0// Use the scrollPercentage as needed (e.g., update a label or send to analytics)print("Scroll Depth: \(scrollDepthPercentage)%") CCplugin.shared.scrollDepth =Int(scrollOffset) CCplugin.shared.scrollDepthPercentage = scrollDepthPercentage }
You need to set the pageLength for the paywall by accessing the pageLength property of the CCPlugin.shared instance and modifying its value.
The debugMode property of the CCPlugin.shared instance can be set to true or false to enable or disable debug mode. When debug mode is enabled, toasts will be shown if the content ID or client ID entered is incorrect. This is useful for development purposes.
CCplugin.shared.debugMode =false
Initialize the paywall
In order to ensure that the Conscent.ai Paywall appears on the targeted pages and the deep insights and analytics are collected optimally you need to implement the following method on all the content/article pages.
To use Google login functionality you need to install pod in your project.
pod 'GoogleSignIn'
Add your OAuth client ID and custom URL scheme
Update your app's Info.plist file to add your OAuth client ID and a custom URL scheme based on the reversed client ID.
The reversed client ID is your client ID with the order of the dot-delimited fields reversed. This is also shown under "iOS URL scheme" when selecting an existing iOS OAuth client in the Cloud console. For example: com.googleusercontent.apps.1234567890-abcdefg
This will be your article or content id for which detail needs to be checked.
parentView
Pass the view on which you are going to show your content.
completionDelegate
This will be used to handle the success and failure cases. Pass the class as the delegate where you want to handle success or failure. This delegate is of the protocol CCPluginCompletionHandlerDelegate, which has three methods: purchasedOrNot(accessTime), success(accessType), onPaywallVisible(paywallType, paywallDisplayType, paywallHeight),loginSuccess(message, userId, authToken), failure(message)
subscriberDelegate(optional)
This is an optional callback that will be called if you pass your class as its delegate. It will be triggered when the subscription button is tapped. If you don't pass it in your delegate, it will not show the subscription view.
subscriberDelegate, which has one method: subscribeBtnTap() which will be triggered whenever the user clicks the Subscribe Button.
signInDelegate(optional)
This is an optional callback that will be called if you pass your class as its delegate. It will be triggered when the sign-in button is tapped. If you don't pass it in your delegate, it will not show the sign-in view.
signInDelegate, which has one method: signInTap() that will be triggered when the user clicks the signin button.
eventParamsDelegate(optional)
This will be used to get the events params. Pass the class as the delegate where you want to handle success. This delegate is of the protocol CCPluginEventParamsDelegate, which has methods: success(paywallId: String, contentId: String, paywallType: String, clientId: String, anonId: String) that will be triggered in case of google login click.
googleLogInDelegate(optional)
This will be used to trigger your Google sign. This delegate is of the protocol CCPluginGoogleLogInDelegate, which has methods: startGoogleLogin() that will be triggered in case of google login click.
Mandatory Step
In your Project go to your target and in the URL types add a new one with URL schemes "conscent".
This is important to handle redirection or app launches from the browser.
call below function inside of openURLContexts scene delegate(inbuilt in iOS).