Skip to content

Management5Exceptions/Demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

Integration Of Appylar For iOS

Appylar is an SDK framework created by Appylar that provides ad-serving capabilities for iOS mobile applications.

Implementation Guide for Developers:

  1. About Appylar
  2. Ad Types
  3. General Requirements
  4. Implementation
  5. Sample Codes

About Appylar

Appylar is a lightweight and user-friendly SDK for integrating ads into iOS applications, developed by Appylar. With this SDK, developers can easily integrate Appylar Ads into any type of iOS app

Built With

Ad Types

Appylar offers multiple ad types and provides developers with the flexibility to place ads anywhere within their application. The ad types available with Appylar are banners and interstitials.

General Requirements

  • Appylar requires a minimum targeted version of iOS 12.0 or later.

Implementation

To use Appylar Ads in your application, you need to follow these steps. Please note that additional implementation steps may be required based on your specific use case:

Pod Installation

Adding Pods to an Xcode project

  • Open a terminal window, and $ cd into your project directory.
  • Create a Podfile. This can be done by running $ pod init.
  • Add a CocoaPod by specifying pod '$Appylar' on a single line inside your target block.
    target ‘App Name’ do
    pod 'Appylar'
    end
    
  • Save your Podfile.
  • Run $ pod install
  • Open the MyApp.xcworkspace that was created. This should be the file you use everyday to create your app.

Add Appylar

Before proceeding with Appylar Ads integration, ensure that the Pods directory is available in your project. Once confirmed, you can import the necessary class into your UIViewController class

import SwiftUI
import Appylar

Back To Top

Setup the configuration for your App and Listeners

  1. To implement Appylar Ads in your iOS application, create an extension of App and init SDK. Additionally, implement the AppylarDelegate protocol within this extension. If you already have an application subclass in your project, you can use that instead.
import SwiftUI
import Appylar
@main
struct DemoApp: App {
    init() {
        AppylarManager.setEventListener(delegate: self, bannerDelegate: self, interstitialDelegate: self)
        AppylarManager.Init(appKey: "OwDmESooYtY2kNPotIuhiQ", adTypes: [.interstitial, .banner], testMode: true)
    }
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

//Attach callbacks for initialization
extension DemoApp: AppylarDelegate{
    func onInitialized() {
        print("onInitialized")
    }
    
    func onError(error: String) {
        print("onError:\(error)")
    }
}
  1. Initialize SDK with configuration:
import SwiftUI
import Appylar

@main
struct DemoApp: App {
    init() {
        AppylarManager.setEventListener(delegate: self, bannerDelegate: self, interstitialDelegate: self)
        AppylarManager.Init(                        
          		app_Key: "<YOUR_APP_KEY>"?? “”, //APP KEY provided by console for Development use
 			Adtypes: [AdType.BANNER, AdType.INTERSTITIAL],	//Types of Ads to integrate
			testmode: true // ‘True’ for development and ‘False’ for production, 
			)
          }
var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Implementation of Banner

  1. To integrate the BannerView component into your design, you need to prepare a view from the contentView and set it to the BannerView type. Follow these steps:
 @State private var bannerView = BannerView()
  1. Implement callback for banners.
//Attach callbacks for banner.
extension DemoApp: BannerViewDelegate {
    func onNoBanner() {
        print("onNoBanner()")
    }
    
    func onBannerShown() {
        print("onBannerShown()")
    }
}
  1. Check Ad availability and show the Ad.
    For better performance and check the availability of ads you can canShowAd() function.
if BannerView().canShowAd(){
       bannerView.showAd()
}

The parameter placement is optional, and it is up to the developer to decide whether to pass it or not.

  1. For creating a BannerView as a representable, you need to define a struct that extends UIViewRepresentable.
struct BannerViewWrapper: UIViewRepresentable {
     let bannerView: BannerView

     func makeUIView(context: Context) -> UIView {
            bannerView
     }
    
     func updateUIView(_ uiView: UIView, context: Context) {
     }
}
  1. To integrate the banner into your SwiftUI ContentView, you can use the following code:
BannerViewWrapper(bannerView: bannerView)
  1. To hide the banner.
 bannerView.hideBanner()

Back To Top

Add Interstitial Ads

  1. Make your a new swift file in which create a class of type InterstitialViewController.
class interstitialViewController:InterstitialViewController
  1. Implement callbacks for Interstitial.
//Attach callbacks for interstitial.
extension DemoApp: InterstitialDelegate {
    func onNoInterstitial() {
        print("onNoInterstitial()")
    }
    
    func onInterstitialShown() {
        print("onInterstitialShown()")
    }
    
    func onInterstitialClosed() {
        print("onInterstitialClosed()")
    }
}
  1. Check Ad availablity and show the Ad.
    For better performance and check the availability of ads you can canShowAd() function and call the showAd method in viewDidLoad() in a class which is a type of InterstitialViewController.
 if InterstitialViewController.canShowAd(){
         self.showAd()
  }

The parameter placement is optional, and it is up to the developer to decide whether to pass it or not.

  1. For lock the orientation of interstitial in your DemoApp and override a function in it.
class AppDelegate: NSObject, UIApplicationDelegate {
    static var orientationLock = UIInterfaceOrientationMask.all {
        didSet {
            if #available(iOS 16.0, *) {
                UIApplication.shared.connectedScenes.forEach { scene in
                    if let windowScene = scene as? UIWindowScene {
                        windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: orientationLock))
                    }
                }
                UIViewController.attemptRotationToDeviceOrientation()
            } else {
                if orientationLock == .landscape {
                    UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation")
                } else {
                    UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
                }
            }
        }
    }
    
    func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
        if Session.isInterstitialShown{
            return AppDelegate.orientationLock
        }else{
            return AppylarManager.supportedOrientation
        }
    }
}

To override a function in your DemoApp file, you can refer to the AppDelegate class and override the corresponding function within it.

 @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
  1. To create an InterstitialView as a representable, you need to define a struct that extends UIViewControllerRepresentable.
struct MyView: UIViewControllerRepresentable {
    typealias UIViewControllerType = AddViewController
    
    func makeUIViewController(context: Context) -> AddViewController {
        let vc = AddViewController()
        return vc
    }
    
    func updateUIViewController(_ uiViewController: AddViewController, context: Context) {
    }
}
  1. To integrate the interstitial ad into your SwiftUI ContentView, you can use the following code:
interstitialViewRepresentable()
  1. To lock the orientation of the interstitial ad when using it as a view representable, apply the following code within the .onAppear and .onDisappear modifiers.
interstitialViewRepresentable()
             .onAppear{
                  if currentOrientation.isLandscape{
                      if currentOrientation == .landscapeLeft {
                           AppDelegate.orientationLock = .landscapeRight
                      }else if currentOrientation == .landscapeRight {
                           AppDelegate.orientationLock = .landscapeLeft
                      }
                   }else{
                           AppDelegate.orientationLock = .portrait
                   }     
             }
             .onDisappear{
                   NotificationCenter.default.post(name: UIDevice.orientationDidChangeNotification, object: nil)
                   AppDelegate.orientationLock = .all
                   currentOrientation = UIDevice.current.orientation
             }

Back To Top

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published