Appylar is an SDK framework created by Appylar that provides ad-serving capabilities for iOS mobile applications.
Implementation Guide for Developers:
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
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.
- Appylar requires a minimum targeted version of iOS 12.0 or later.
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:
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.
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
- 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)")
}
}
- 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()
}
}
}
- 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()
- Implement callback for banners.
//Attach callbacks for banner.
extension DemoApp: BannerViewDelegate {
func onNoBanner() {
print("onNoBanner()")
}
func onBannerShown() {
print("onBannerShown()")
}
}
- Check Ad availability and show the Ad.
For better performance and check the availability of ads you cancanShowAd()
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.
- 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) {
}
}
- To integrate the banner into your SwiftUI ContentView, you can use the following code:
BannerViewWrapper(bannerView: bannerView)
- To hide the banner.
bannerView.hideBanner()
- Make your a new swift file in which create a class of type
InterstitialViewController
.
class interstitialViewController:InterstitialViewController
- Implement callbacks for Interstitial.
//Attach callbacks for interstitial.
extension DemoApp: InterstitialDelegate {
func onNoInterstitial() {
print("onNoInterstitial()")
}
func onInterstitialShown() {
print("onInterstitialShown()")
}
func onInterstitialClosed() {
print("onInterstitialClosed()")
}
}
- Check Ad availablity and show the Ad.
For better performance and check the availability of ads you cancanShowAd()
function and call the showAd method in viewDidLoad() in a class which is a type ofInterstitialViewController
.
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.
- 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
- 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) {
}
}
- To integrate the interstitial ad into your SwiftUI ContentView, you can use the following code:
interstitialViewRepresentable()
- 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
}