Integrating tapCLIQ SDK in Swift apps


Table of contents


  1. Integrating tapCLIQ SDK in a Swift App
  2. Setting up Ad View

 

  1. 1. Integrating tapCLIQ SDK in a Swift App


    Step 1: Copy t2rBundle.bundle to the "Resources" folder in your project. Select "Copy items into destination group's folder (if needed)" in the pop up that follows once you drag the images into the Resources folder.

    Step 2: Copy libtapcliqiOSSDK.a into the project's root folder.

    Step 3: On the left hand side of XCode, in the file browser, click on the main project file. The right hand side view will expand the details.

    Select target and expand "Build Phases", under it, expand "Link Binary with Libraries".

    Add the following libraries:

    NOTE:
    AdSupport framework should be added for iOS 6 and higher (and so if your app supports lower version than it should be weakly linked i.e., Optional - as shown in the image below)


    [Figure: 1 ]

     

    Step 4: If "libt2rLibrary.a" does not show up in the "Link Binary with Libraries" tab, click on the '+' sign on the bottom left corner and click on "Add Other". Browse to libt2rLibrary.a which is copied in your project's root ( in step 2 ) and add it.

    Step 5: Copy AdvBar.h to the "Classes" folder. Select "Copy items into destination group's folder (if needed)".

    Step 6: Add a Bridging header to your project (if you do not already have one). Usually it is "ProductName-Bridging-Header.h". Add #import AdvBar.h in it (as shown below)


    Step 7: Specify path of your bridging header under "Build Settings / Swift Compiler - Code Generation / Objective-C Bridging Header" as shown in the image below


     

  2. 2. Setting up Ad view


    Step 1: Add below mentioned line to your ViewController.swift file wherein you wish to integrate tapcliq ad view.

    class ViewController: UIViewController, AdvBarProtocol {
    	var ab : AdvBar!
    }
    

    Put the below mentioned code in viewDidAppear func of the view controller (Ad initialization followed by ad request notification, with your tag)

     

    override func viewDidAppear(animated: Bool) 
    {
    	super.viewDidAppear(true);
    	
    	let APP_ID: String = "a7380cf91c5347b688ea351c5d78157q"
    	let AD_TYPE: String = "PU"
    	let AD_TAG: String = "testge"
    	let ORIGIN: CGPoint = CGPointMake(0.0, self.view.frame.size.height - 300.0)
    	ab = AdvBar(appId: APP_ID, origin: ORIGIN, from: self, webadType: AD_TYPE, adUnitId: 0, tag: AD_TAG)
    	ab.mydelegate = self
    	ab.tag = 13131313
    	ab.layer.borderColor = UIColor.blackColor().CGColor
        ab.layer.borderWidth = 2.0
    	self.view.addSubview(ab)
    	
    	var dict : NSDictionary = NSDictionary(objects: ["testge",AD_TYPE], forKeys: ["Tags","AdType"])
    	
    	NSNotificationCenter.defaultCenter().postNotificationName("CustomTrigger", object: self, userInfo: dict as Dictionary)
    
    }

     


    Based on the type of ad view you wish to integrate, AD_TYPE can be "PU" (for 720 x 300), "MR" (for 300 x 250), "HP" (for 300 x 600), @"Square_Ad" or @"FullScreen_Ad" or @"700x90" (Detail View of a SplitViewController) or @"1024x90" (Full Width) or @"Small_Ad" (for a 320x50 ad)

    Ad unit Id is the unit Id registered by you in under your app -

    NOTE:
    To get an App Id you need to sign in to your account and register your app under "My Apps" from left hand side panel.

    And Implement fetchNewAdPacket (delegate method) and post a custom trigger in that method, if you wish to constantly fetch new ad packets.

     

    func fetchNewAdPacket(adView: AdvBar) 
    {
    	var dict : NSDictionary = NSDictionary(objects: ["Shopping"], forKeys: ["Tags"])
    	NSNotificationCenter.defaultCenter().postNotificationName("CustomTrigger", object: self, userInfo: dict)
    }				  
    

     

    NOTE:
    Pop under - PU (720 x 300), Half Page - HP (300 x 600), 700x90 and 1024x90 Ad formats are only available for iPad

    Delegate methods :
    You can implement following optional delegate methods which notify your app when:

     

    func presentT2RBar(adView: AdvBar) -> BOOL {
    // tapCLIQ ad view is about to be displayed.
    }
    func removedT2RBar(adView: AdvBar) {
    // tapCLIQ ad view is about to be removed from the view.
    }
    func changeAd(adView: AdvBar) {
    // Ad is going to change.
    }
    func fetchNewAdPacket(adView: AdvBar) {
    // Called when tapCLIQ is about to fetch a new ad packet
    }
    fun getUserSelection(data: String) {
    // Called to notify user's selection in a Question-Answer ad ( by passing a tag / link )
    }
    - func adError(description: String) {
    // Called when their is error with any tapCLIQ request
    }
    

     

     

  3.  

Back to Top