SmartAd is an easy-to-use library for AdMob and Audience Network advertising frameworks on iOS and Android.
SmartAd is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SmartAd'
pod 'Firebase/Core'
pod 'Firebase/AdMob'
pod 'FBAudienceNetwork'
- XCode 9.3
- Swift4
- FirebaseCore (4.0.19)
- Google-Mobile-Ads-SDK (7.30.0)
- FBAudienceNetwork (4.28.1)
- AdView
- InterstitialAd
- RewardedVideoAd
- AdView
- InterstitialAd
- RewardedVideoAd
If you add a view in the StoryBoard, change the custom view to 'SmartAdBanner' and then set the properties only, it will work without coding.
If you want to return a return value, set the delegate and implement SmartAdBannerDelegate as follows.
extension ViewController: SmartAdBannerDelegate {
func smartAdBannerDone(_ view: SmartAdBanner) {
// Success...
}
func smartAdBannerFail(_ error: Error?) {
// Fail...
}
}
* Note: In order for the isAutoHeight value to be applied, the Height value must be assigned to the AutoAdBanner's Auto Layout. When the advertisement of each platform is loaded, the Height value is corrected according to the advertisement size. If it fails, the value is set to 0 and it is not displayed on the screen.
* Note: The SmartAdBanner will display normally if the minimum width is greater than 300 or 320, depending on the size format.
Here is the example code that calls the interstitial.
var interstitialAd: SmartAdInterstitial?
override func viewDidLoad() {
super.viewDidLoad()
interstitialAd = SmartAdInterstitial(self, adOrder: .random,
googleID: "googleID", facebookID: "facebookID")
interstitialAd?.loadAd()
}
Use SmartAdInterstitialDelegate if you want to return the result.
extension ViewController: SmartAdInterstitialDelegate {
func smartAdInterstitialDone() {
// Success...
}
func smartAdInterstitialFail(_ error: Error?) {
// Fail...
}
}
Functions of the SmartAdInterstitial class
public convenience init(_ controller: UIViewController, adOrder: SmartAdOrder,
googleID: String?, facebookID: String?, isShowAfterLoad: Bool = true)
public convenience init(_ controller: UIViewController, adOrder: SmartAdOrder,
googleID: String?, facebookID: String?)
public func loadAd(delayMilliseconds: Double = 0.0)
public func showAd() -> Bool
Here is the example code that calls the award ad.
var awardAd: SmartAdAward?
override func viewDidLoad() {
super.viewDidLoad()
awardAd = SmartAdAward.init(self, adOrder: .google, googleID: "googleID", facebookID: "facebookID")
awardAd?.showAd()
}
Use SmartAdAwardDelegate if you want to return the result.
extension ViewController: SmartAdAwardDelegate {
func smartAdAwardDone(_ isGoogle: Bool, _ isAwardShow: Bool, _ isAwardClick: Bool) {
// Success...
}
func smartAdAwardFail(_ error: Error?) {
// Fail...
}
}
Functions of the SmartAdAward class
public convenience init(_ controller: UIViewController, adOrder: SmartAdOrder,
googleID: String?, facebookID: String?)
public func showAd()
SmartAdAlertController.alert(self,
adOrder: .random,
googleID: "googleID",
facebookID: "facebookID",
title: "Alert") { (_) in
// Clicked OK
}
Alert with OK & Cancel.
SmartAdAlertController.confirm(self,
adOrder: .google,
googleID: "googleID",
facebookID: "facebookID",
title: "Confirm") { (isOK) in
if isOK {
// Clicked OK
} else {
// Clicked Cancel
}
}
Customizing Alert.
SmartAdAlertController.select(self,
adOrder: .facebook,
googleID: "googleID",
facebookID: "facebookID",
title: "Select",
titleOK: "Yes",
titleCancel: "No") { (isOK) in
if isOK {
// Clicked Yes
} else {
// Clicked No
}
}
SmartAd.addTestDevice(type: .google, ids: [kGADSimulatorID, "XXXXX"])
SmartAd.addTestDevice(type: .facebook, ids: ["XXXXX","YYYYY"])
You can register and use this function to stop ads in-app billing or under certain circumstances.
SmartAd.IsShowAdFunc = { () in
// You can customize the content to suit your situation.
// Here's an example that applies to all ad classes except SmartAdAward.
let def = UserDefaults.standard
let isShowAd = def.bool(forKey: "isShowAd")
return ([SmartAdBanner.self, SmartAdInterstitial.self, SmartAdAlertController.self], isShowAd)
}
The MIT License
Copyright (c) 2009-2017 ShockUtility.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.