Conscent.ai Developer Documentation
  • Version 2.0
    • Using Conscent.ai
    • Web SDK
    • Login
    • Logout
    • User Details Drawer
    • Google One Tap
    • Mobile SDK
      • iOS(Swift)
        • In-App Purchases with Conscent
      • Android SDK
      • React Native SDK
      • Google In-App Purchases with Conscent
      • Apple In-App Purchases with Conscent
    • Facebook SSO Integration Guide
    • Landing Page API v 2.0
    • AMP Integration
    • Integrating APIs(v2)
      • Purchase Details
      • User Registered Or Not
      • User Registrations
      • Subscription Plans Details
      • Get User Details
      • Add Subscription If User Registered
      • Update UserDetails
      • Update SubscriptionDetails
      • Get All Transaction Details
    • IAM System API Documentation
  • Version 1.0
    • Getting Started
    • On Board
    • Using Conscent.ai
    • Authentication
    • Web SDK
    • Login
    • Logout
    • Amp Documentation
    • Mobile SDK
      • Android
      • Flutter
      • iOS(Swift)
      • React Native SDK
    • Auto Login
    • Creating External Purchases
    • Landing Page API
  • Login Screen Customization
  • Integrating Client Payment Gateway
  • Integrating with APIs
    • User Details and Subscriptions Information
    • Purchased Subscriptions
    • User and Purchase Details
    • Client Purchases
    • Client Micropayments
    • Client Passes
    • Cancel Active Subscriptions
    • Delete User
  • Events API Docs
    • Different Types of Events
    • SSO Login Flow
  • Discount Coupon
    • Dynamic Coupon API Generation:
  • New Webhooks
    • Meter Banner Webhook
    • Paywall Webhook
    • SignUp Webhook
    • Refund Webhook
    • Purchase Webhook
    • Subscription Landing Page Webhook
    • Popup Webhook
    • User Update Webhook
    • Payment Gateway Webhook
    • Review Page Webhook
    • Transaction Webhook
    • Login Webhook
    • Cancel Subscription Webhook
  • Old Webhooks
    • Sign Up Webhook
    • Login Webhook
    • Subscription Payment Webhook
    • Subscription Cancelled Webhook
    • Pass Payment Webhook
    • Subscription Bundle Payment Webhook
    • Review Subscription Webhook
    • Micro Payment Webhook
    • How to validate Webhooks?
  • Registering The Content
    • Create Content
    • Edit Content
    • View Content
  • Country Code List
  • Supported Currencies and Payment Gateways
    • Stripe Supported Country with Currency
    • Razorpay Supported Country with Currency
    • Paypal Supported Country with Currency
  • Errors
  • Loyalty System
    • Web SDK
    • iOS SDK
    • Android SDK
    • Flutter SDK
    • API from server
Powered by GitBook
On this page
  1. Version 2.0
  2. Mobile SDK

iOS(Swift)

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.

PreviousMobile SDKNextIn-App Purchases with Conscent

Last updated 3 months ago

Pre-requisites

Conscent.ai iOS SDK supports iOS 13.0 and above.

Installation Steps

You can download the CCPlugin.xcframework File from and add it to your project.

Make sure you change the embed mode for CCPlugin.xcframework to "Embed & Sign".

Initialize the SDK
  1. Import the CCPlugin framework into your ViewController class.

import CCPlugin
  1. Configure the SDK in didFinishLaunchingWithOptions in AppDelegate class

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  // Configure the SDK
  CCPlugin.shared.configure(mode: .sandbox, clientID: "your-client-id")
  // ApplicationDelegate needs to be only called in case of Facebook Login
  ApplicationDelegate.shared.application(
                    application,
                    didFinishLaunchingWithOptions: launchOptions
                )
  // Additional configurations if necessary
  return true
}
  • yourClientId - Pass your clientId received from Conscent.ai.

  • Mode - configuration testing of different environments available.

Api Mode can be set as :
   Mode.sandbox
   Mode.production
  1. 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 depth
let screenHeight = scrollView.bounds.height
let scrollDepth: Int = Int(scrollView.contentOffset.y)
CCplugin.shared.scrollDepth = scrollDepth
  1. You have to confirm UIScrollViewDelegate and you need to set scrollDepth and scrollDepthPercentage.

  func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    let scrollDepth: Int = Int(scrollView.contentOffset.y)
    CCplugin.shared.scrollDepth = scrollDepth
    let contentHeight = scrollView.contentSize.height
    let scrollViewHeight = scrollView.bounds.height
    let scrollOffset = scrollView.contentOffset.y
    // Calculate the scroll percentage
    let 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
  }
  func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
    let contentHeight = scrollView.contentSize.height
    let scrollViewHeight = scrollView.bounds.height
    let scrollOffset = scrollView.contentOffset.y
    // Calculate the scroll percentage
    let 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
  }
  1. You need to set the pageLength for the paywall by accessing the pageLength property of the CCPlugin.shared instance and modifying its value.

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    debugPrint("pageLength:\(scrollView.contentSize.height)")
    CCplugin.shared.pageLength = Int(scrollView.contentSize.height)
  }

Enabling the debug mode:

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.

 CCplugin.shared.showPayWall(contentID: contentID,
                    variables: ["packageName":"cc.plugin.com", "device":"IOS"],
                    title: contentID,
                    categories: ["category1","category2","category3"] ,
                    sections: ["section12","section14"],
                    tags: ["premium"],
                    contentUrl: "https://www.google.com/",
                    authorName: "abc",
                    publicationDate: "2024-07-17T11:57:27.312Z",
                    parentView: view,
                    navigationController: self.navigationController,
                    eventParamsDelegate: self,
                    googleUserLogInDelegate: self,
                    completiondelegate: self,
                    signInDelegate: self
      )                                   

Google Login Process
  1. To use Google login functionality you need to install pod in your project.

pod 'GoogleSignIn'
  1. 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 . For example: com.googleusercontent.apps.1234567890-abcdefg

<key>GIDClientID</key>
<string>YOUR_IOS_CLIENT_ID</string>
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>YOUR_DOT_REVERSED_IOS_CLIENT_ID</string>
    </array>
  </dict>
</array>
  1. To initiate a Google login

CCplugin.shared.configure(mode: .sandbox, clientID: clientID)
CCplugin.shared.googleUserLogIn(controller: self, googleUserLogInDelegate: self)
Facebook Login
  1. To use Facebook login functionality you need to install a pod in your project.

pod 'FBSDKLoginKit', '17.4.0'
pod 'FBSDKShareKit', '17.4.0'
  1. Update didFinishLaunchingWithOptions with the below code in Apthe pDelegate class.

 ApplicationDelegate.shared.application(
                    application,
                    didFinishLaunchingWithOptions: launchOptions
                )
  1. To integrate Facebook Login into your iOS application, update your app's Info.plist file with the following entries. Replace the placeholders with the appropriate values from your Facebook app configuration.

Required Entries for Facebook Login

<key>FacebookAppID</key>
<string>YOUR_FACEBOOK_APP_ID</string>
<key>FacebookClientToken</key>
<string>YOUR_FACEBOOK_CLIENT_TOKEN</string>
<key>FacebookDisplayName</key>
<string>YOUR_FACEBOOK_APP_DISPLAY_NAME</string>
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fbYOUR_FACEBOOK_APP_ID</string>
        </array>
    </dict>
</array>
Parameters
Description

contentID (string)

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).

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    if let url = URLContexts.first?.url {
       CCplugin.shared.handleRelaunchApp(url: url)
    }
}

You need to call CCplugin.shared.exitSDK() while leaving the scope of current controller.

override func willMove(toParent parent: UIViewController?) {
    super.willMove(toParent: parent)
    if parent == nil {
      // Back button action was triggered
      debugPrint("Back button pressed")
      CCplugin.shared.exitSDK()
    }
  }

Call the below function and pass the userId, after the user has logged in:

CCplugin.shared.setClientUserId(clientUserId: "Your_User_Id")
Login Functionality
CCplugin.shared.configure(mode: .sandbox, clientID: clientID)
CCplugin.shared.userLogIn(userLogInDelegate: self)

CCPluginUserLogInDelegate

extension AccountViewController: CCPluginUserLogInDelegate {
  func userLogInSuccess(message: String, userId: String, authToken: String)
   {
    debugPrint("message: \(message), userId: \(userId), authToken: \(authToken)")
    }  
  func userLogInFailure(message: String, errorCode: String) {
        debugPrint(" message: \(message), errorCode: \(errorCode)")
        }
  func redirectToHomeScreen(message: String){
       debugPrint(" message: \(message)")
  }
}

To enable Apple login follow either of these steps:

Xcode Steps:

  1. Open Xcode project.

  2. Go to Target Settings → Signing & Capabilities.

  3. Add "Sign in with Apple" capability.

  4. Verify entitlements.

  5. Ensure proper signing.

App Store Connect Steps:

  1. Select the app under "My Apps."

  2. Go to "App Information."

  3. Add "Sign in with Apple" information (privacy policy and terms of service URLs).

  4. Enable "Sign in with Apple."

  5. Submit changes for review.

Fetch User-details
CCplugin.shared.openUserDetails(userProfileDelegate: self)
CCplugin.shared.getUserDetail(completiondelegate: self)

CCPluginUserDetailsDelegate

extension AccountViewController: CCPluginUserDetailsDelegate {
    func success(userDetails: CCPlugin.UserDetails) 
    {
    debugPrint("PhoneNo.: \(userDetails.phoneNumber ?? "") Email: \(userDetails.email ?? "") Name: \(userDetails.name ?? "")")     
    }
    
    func failure(message: String, errorCode: String) 
    {
    debugPrint(" message: \(message), errorCode: \(errorCode)")
    }
    func userProfileUpdated(message: String, statusCode: String)
    {
    debugPrint("Message: \(message) statusCode:\(statusCode)")
    }
}

CCPluginUserProfileDelegate:

Note: Use these messages to handle Logout in UserProfile Logout.

USER_LOGOUT_SUCCESS

USER_LOGOUT_FAILED

USER_DELETE_ACCOUNT_SUCCESS

USER_DELETE_ACCOUNT_FAILED

extension AccountViewController: CCPluginUserProfileDelegate{
    func success(message: String, statusCode: String) {
        debugPrint("Message: \(message) statusCode:\(statusCode)")
    }
    
    func failure(message: String, errorCode: String) {
        debugPrint("Message: \(message) errorCode:\(errorCode)")
    }
    
}
Custom Logout Functionality

Custom Logout Functionality refers to a logout process that is specifically designed and implemented based on a client’s requirements

CCPluginUserLogOutDelegate:

Pass the class as the delegate where you want to handle success or failure.

This delegate is of the protocol CCPluginlogout, which has two methods:

success() and failure() that will be triggered in case of success and failure of the process.

CCplugin.shared.userLogout(userLogOutDelegate: self)
extension AccountViewController: CCPluginlogout {
    func userLogOutSuccess() {
        debugPrint("loginSuccess")
    }
    
 func userLogOutFailure(message: String, errorCode: String) {
        debugPrint(" \(message), \(errorCode)")
        
    }
}

To use only the Subscription Landing Page, call the below method:

CCplugin.shared.openCustomUrl(customUrl: String)

CustomUrl is URL of the Subscription Landing Page with clientId.

Go to .

Demo APP

here
selecting an existing iOS OAuth client in the Cloud console
App Store Connect
Link
Atached a screenshot for the reference: